【发布时间】:2020-12-18 21:13:52
【问题描述】:
我是苗条的新手,所以请多多包涵。 我有类似的项目结构
\slim
\public
index.php
\src
\controllers
\reports
BillingReportController.php
\routes
router.php
\config
db.php
但是每当我通过路由调用控制器时,都会出现以下错误
“PHP 致命错误:在第 13 行的 /var/www/html/apimod/public/index.php 中找不到类 'src\controllers\reports\BillingReportController'”
至于错误提到的那一行sn-p如下。
index.php
$container = $app->getContainer();
$container['BillingReportController'] = function($container){
return new \src\controllers\reports\BillingReportController;
};
router.php
$app->group('/report', function() use ($app) {
$app->get('/billing', 'BillingReportController:billing');
});
BillingReportController.php
namespace src\controllers\BillingReportController;
class BillingReportController{
public function billing($request, $response){
//my code goes here
}
}
谁能指出错误。
【问题讨论】:
-
认为你的控制器的命名空间不正确
namespace src\controllers\BillingReportController. -
那我应该用什么?
-
因为它在一个名为报告的目录中,可能是
src\controllers\reports -
不高兴。错误仍然存在。
标签: php routes controller slim-3