[英]Slim PHP Framework Controller Directory
I'm using Slim Framework for a new app and I want a controller directory in my src folder. 我正在为新应用程序使用Slim Framework,并且我想在src文件夹中找到一个控制器目录。 I keep getting the error message: 我不断收到错误消息:
Callable \App\Controllers\MobileApiController does not exist
dependencies.php 依靠.php
$container['MobileApiController'] = function ($c)
{
return new \App\Controllers\MobileApiController;
};
routes.php routes.php
$app->get('/user', '\App\Controllers\MobileApiController:getUser');
MobileApiController.php MobileApiController.php
<?php
namespace App\Controllers;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
class MobileApiController
{
protected $container;
public function __construct($c) {
$this->container = $c;
}
public function getUser($request, $response, $args)
{
var_dump($request);
}
}
composer.json composer.json
"autoload-dev": {
"psr-4": {
"App\\": "src/",
"Tests\\": "tests/"
}
},
The 'src' folder has a 'Controllers' folder and 'routes.php' and 'dependencies.php' files “ src”文件夹具有“ Controllers”文件夹以及“ routes.php”和“ dependencies.php”文件
Usually the namespace Test
(singular) or App\\Test
is dev-related only and App
is prod and dev-related. 通常,名称空间Test
(单数)或App\\Test
仅与开发相关,而App
与prod和开发相关。 The App\\Test
namespace belongs to autoload-dev
and App
belongs to autoload
. App\\Test
命名空间属于autoload-dev
而App
属于autoload
。
Example (composer.json): 示例(composer.json):
"autoload": {
"psr-4": {
"App\\": "src/"
},
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests/"
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.