我尝试过:
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#prefix-routing https://book.cakephp.org/3.0/en/development/routing.html#changing-the-controller-actions-used https://book.cakephp.org/3.0/en/development/routing.html#creating-restful-routes
和
https://book.cakephp.org/3.0/en/development/routing.html#mapping-additional-resource-routes
$ 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} |