Php 在slim 3中找不到控制器
我是新来斯利姆的,所以请容忍我。 我的项目结构如下Php 在slim 3中找不到控制器,php,routes,controller,slim-3,Php,Routes,Controller,Slim 3,我是新来斯利姆的,所以请容忍我。 我的项目结构如下 \slim \public index.php \src \controllers \reports BillingReportController.php \routes router.php \config db.php 但每当我通过路由呼叫控制器时,它都会给出以下错误 “PHP致命错误:在第13行的/var
\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'”
对于错误中提到的行,代码段如下所示
index.php
$container = $app->getContainer();
$container['BillingReportController'] = function($container){
return new \src\controllers\reports\BillingReportController;
};
$app->group('/report', function() use ($app) {
$app->get('/billing', 'BillingReportController:billing');
});
namespace src\controllers\BillingReportController;
class BillingReportController{
public function billing($request, $response){
//my code goes here
}
}
router.php
$container = $app->getContainer();
$container['BillingReportController'] = function($container){
return new \src\controllers\reports\BillingReportController;
};
$app->group('/report', function() use ($app) {
$app->get('/billing', 'BillingReportController:billing');
});
namespace src\controllers\BillingReportController;
class BillingReportController{
public function billing($request, $response){
//my code goes here
}
}
BillingReportController.php
$container = $app->getContainer();
$container['BillingReportController'] = function($container){
return new \src\controllers\reports\BillingReportController;
};
$app->group('/report', function() use ($app) {
$app->get('/billing', 'BillingReportController:billing');
});
namespace src\controllers\BillingReportController;
class BillingReportController{
public function billing($request, $response){
//my code goes here
}
}
任何人都可以指出错误。您必须在作曲家中使用自动加载。像这样的
"autoload": {
"psr-4": {
"src\\": "src"
}
}
然后在终端中输入此命令
composer dump-autoload
它应该可以解决您的问题认为控制器的名称空间不正确
名称空间src\controllers\BillingReportController
。那么我应该使用什么?因为它位于名为reports的目录中,可能src\controllers\reports
没有乐趣。错误仍然存在。