Маршрутизация с ресурсами и областью действия не работает с сопоставленным POST
Что я пробовал:
Router::scope('/v1', function ($routes) {
// ...
$routes->resources('Auth', [
'map' => [
'login' => [
'action' => 'login',
'method' => 'POST',
'path' => 'login'
]
],
'only' => ['login']
]);
});
У меня есть контроллер Auth, из-за дизайна я не могу использовать UsersController для выполнения входа в систему.
Что я ожидаю:
POST to /v1/auth/login
должен возвращать True или False (механизм уже добавлен в действие.
Что я получаю:
Недостающий маршрут
RTFM выполнил:
https://book.cakephp.org/3.0/en/development/routing.html https://book.cakephp.org/3.0/en/development/routing.html https://book.cakephp.org/3.0/en/development/routing.html
а также
https://book.cakephp.org/3.0/en/development/routing.html
$ tail debug.log
Cake\Error\ExceptionRenderer::render() - CORE/src/Error/ExceptionRenderer.php, line 200
Cake\Error\Middleware\ErrorHandlerMiddleware::handleException() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 110
Cake\Error\Middleware\ErrorHandlerMiddleware::__invoke() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 94
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
Cake\Http\Runner::run() - CORE/src/Http/Runner.php, line 51
Cake\Http\Server::run() - CORE/src/Http/Server.php, line 80
[main] - ROOT/webroot/index.php, line 37
Версия: 3.4.13
error.log
2018-02-20 10:26:35 Warning: DebugKit not enabled. You need to either install pdo_sqlite, or define the "debug_kit" connection name.
2018-02-20 10:26:35 Error: [Cake\Routing\Exception\MissingRouteException] A route matching "/login" could not be found.
Exception Attributes: array (
'url' => '/login',
)
Request URL: /login
Stack Trace:
#0 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Router.php(368): Cake\Routing\RouteCollection->parseRequest(Object(Cake\Http\ServerRequest))
#1 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(48): Cake\Routing\Router::parseRequest(Object(Cake\Http\ServerRequest))
#2 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#3 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#4 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#5 /var/www/force_api/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(92): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#6 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#7 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#8 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Server.php(80): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#9 /var/www/force_api/webroot/index.php(37): Cake\Http\Server->run()
#10 {main}
2018-02-20 10:26:42 Warning: DebugKit not enabled. You need to either install pdo_sqlite, or define the "debug_kit" connection name.
2018-02-20 10:26:42 Error: [Cake\Routing\Exception\MissingRouteException] A route matching "/v1/login" could not be found.
Exception Attributes: array (
'url' => '/v1/login',
)
Request URL: /v1/login
Stack Trace:
#0 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Router.php(368): Cake\Routing\RouteCollection->parseRequest(Object(Cake\Http\ServerRequest))
#1 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(48): Cake\Routing\Router::parseRequest(Object(Cake\Http\ServerRequest))
#2 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#3 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#4 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#5 /var/www/force_api/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(92): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#6 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#7 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#8 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Server.php(80): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#9 /var/www/force_api/webroot/index.php(37): Cake\Http\Server->run()
#10 {main}
2018-02-20 10:26:53 Warning: DebugKit not enabled. You need to either install pdo_sqlite, or define the "debug_kit" connection name.
2018-02-20 10:26:53 Error: [Cake\Routing\Exception\MissingRouteException] A route matching "/v1/auth/login" could not be found.
Exception Attributes: array (
'url' => '/v1/auth/login',
)
Request URL: /v1/auth/login
Stack Trace:
#0 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Router.php(368): Cake\Routing\RouteCollection->parseRequest(Object(Cake\Http\ServerRequest))
#1 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(48): Cake\Routing\Router::parseRequest(Object(Cake\Http\ServerRequest))
#2 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#3 /var/www/force_api/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#4 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#5 /var/www/force_api/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(92): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#6 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#7 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#8 /var/www/force_api/vendor/cakephp/cakephp/src/Http/Server.php(80): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#9 /var/www/force_api/webroot/index.php(37): Cake\Http\Server->run()
#10 {main}
Я вижу ошибку:
** Также **
$ bin/cake routes | grep auth
| auth:login | /v1/auth/login | {"controller":"Auth","action":"login","_method":"POST","plugin":null} |