我遇到自动加载器没有正确加载类的问题。我不确定我是否正确行事......我正在使用纤薄的框架。
我的composer.json
看起来像这样:
{
"require": {
"slim/slim": "^3.0",
"robmorgan/phinx": "^0.6.6",
"vlucas/phpdotenv": "^2.4",
"philo/laravel-blade": "3.*"
},
"autoload": {
"psr-4": {
"Cipo\\": ["app/"]
}
}
}
我的目录结构:
app/
Controllers/
Console/
AuthController.php
UsersController.php
HomeController.php
Core/
AbstractController.php
router.php
database/
public/
index.php
vendor/
views/
storage/
composer.json
我的router.php
看起来像这样:
$app->get("/", Cipo\Controllers\HomeController::class . ":index");
$app->get("/auth/login", Cipo\Controllers\Console\AuthController::class . ":getLogin");
问题是/
有效且显示正确的HTML,但/auth/login
不起作用。这是抛出的错误:
[Tue Jan 31 14:11:37.758803 2017] [:error] [pid 1336] [client 44.44.44.1:54453] Slim Application Error:
Type: RuntimeException
Message: Callable Cipo\\Controllers\\Console\\AuthController does not exist
File: /var/www/cipo.me/vendor/slim/slim/Slim/CallableResolver.php
Line: 62
Trace: #0 /var/www/cipo.me/vendor/slim/slim/Slim/CallableResolverAwareTrait.php(45): Slim\\CallableResolver->resolve('Cipo\\\\Controller...')
#1 /var/www/cipo.me/vendor/slim/slim/Slim/Route.php(333): Slim\\Routable->resolveCallable('Cipo\\\\Controller...')
#2 /var/www/cipo.me/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(116): Slim\\Route->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))
#3 /var/www/cipo.me/vendor/slim/slim/Slim/Route.php(316): Slim\\Route->callMiddlewareStack(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))
#4 /var/www/cipo.me/vendor/slim/slim/Slim/App.php(438): Slim\\Route->run(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))
#5 /var/www/cipo.me/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(116): Slim\\App->__invoke(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))
#6 /var/www/cipo.me/vendor/slim/slim/Slim/App.php(332): Slim\\App->callMiddlewareStack(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))
#7 /var/www/cipo.me/vendor/slim/slim/Slim/App.php(293): Slim\\App->process(Object(Slim\\Http\\Request), Object(Slim\\Http\\Response))
#8 /var/www/cipo.me/public/index.php(45): Slim\\App->run()
#9 {main}
View in rendered output by enabling the "displayErrorDetails" setting.
AuthController.php
代码段
<?php
namespace Cipo\Controllers\Console;
use PDO;
use Cipo\Core\AbstractController;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Interop\Container\ContainerInterface;
/**
* Class AuthController
* @property \PDO db
* @property \Philo\Blade\Blade blade
*/
class AuthController extends AbstractController
{
// ...
public function getLogin(RequestInterface $request, ResponseInterface $response)
{
$response->getBody()->write($this->blade->view()->make("auth.login")->render());
return $response;
}
}