我创建了一个自定义中间件,并尝试在cakephp 3.5.x中的Cases
下的特定路由范围中使用,
要求:
routes.php文件
use Api\Middleware\CasesMiddleware;
Router::scope('/', function (RouteBuilder $routes) {
$routes->registerMiddleware('CasesRequired', new CasesMiddleware());
Router::scope('/Cases', function (RouteBuilder $routes) {
$routes->applyMiddleware('CasesRequired');
}
}
但这不起作用。但是当我将$routes->applyMiddleware('CasesRequired')
放在路由范围cases
之外时,其工作方式如下,
Router::scope('/', function (RouteBuilder $routes) {
$routes->registerMiddleware('CasesRequired', new CasesMiddleware());
$routes->applyMiddleware('CasesRequired');
Router::scope('/Cases', function (RouteBuilder $routes) {
}
}
请说明出现了什么问题.......只能在路由范围Cases
下调用中间件。
答案 0 :(得分:0)
use Api\Middleware\CasesMiddleware;
Router::scope('/', function (RouteBuilder $routes) {
$routes->registerMiddleware('CasesRequired', new CasesMiddleware());
$routes->scope('/Cases', function ($routes) {
$routes->applyMiddleware('CasesRequired');
}
}