我向容器注册了一个控制器,但它似乎无法工作,因为它与正确的位置不匹配。
\web\index.php
<?php
require __DIR__ . '/vendor/autoload.php';
// Instantiate the app
$app = new \Slim\App(['settings' => ['displayErrorDetails' => true] ]);
$app->get('/', 'App\controllers\HomeController:home');
// Run!
$app->run();\web\App\controllers\HomeController.php
<?php
namespace App\controllers\HomeController;
class HomeController
{
protected $container;
// constructor receives container instance
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
public function __invoke($request, $response, $args) {
// your code
// to access items in the container... $this->container->get('');
return $response;
}
public function home($request, $response, $args) {
// your code
// to access items in the container... $this->container->get('');
return $response;
}
public function contact($request, $response, $args) {
// your code
// to access items in the container... $this->container->get('');
return $response;
}
}因为它显示Slim Application Error:
Slim应用程序错误由于以下错误,应用程序无法运行:
详细信息类型:HomeController消息: Callable App\ RuntimeException \HomeController不存在文件:HomeController行: 90
我的项目文件夹结构:
\web
index.php
\App
\controllers
HomeController.php
\vendor 为什么这是错误的?注意:
发布于 2018-11-28 23:37:47
在\web\App\controllers\HomeController.php
中将
App\controllers\HomeController更改为App\controllershttps://stackoverflow.com/questions/53496349
复制相似问题