CakePHP 3.0
CakePHP 3.0
对于存在的路线,我收到了缺少路线"的错误消息.
I'm getting a "Missing Route" error for a route that exists.
这是我的路线:
#my admin routes...
Router::prefix('admin', function($routes) {
$routes->connect('/', ['controller'=>'Screens', 'action'=>'index']);
$routes->connect('/screens', ['controller'=>'Screens', 'action'=>'index']);
$routes->connect('/screens/index', ['controller'=>'Screens', 'action'=>'index']);
//$routes->fallbacks('InflectedRoute');
});
Router::scope('/', function ($routes) {
$routes->connect('/login', ['controller' => 'Pages', 'action' => 'display', 'login']);
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
$routes->fallbacks('InflectedRoute');
});
Plugin::routes();
基本上我只是将顶部(用于管理路由)添加到开箱即用的默认路由中.
Basically I just added the top section (for admin routing) to the default routes that come out of the box.
当我访问 /admin/screens/index
时,我看到以下错误:
When I visit /admin/screens/index
I see the following error:
注意错误信息说:
错误:匹配array ('action' => 'add', 'prefix' =>'admin', 'plugin' => NULL, 'controller' => 'Screens', '_ext' => NULL,)"无法找到.
Error: A route matching "array ( 'action' => 'add', 'prefix' => 'admin', 'plugin' => NULL, 'controller' => 'Screens', '_ext' => NULL, )" could not be found.
...这很奇怪,因为我没有尝试访问 add
操作.下面打印的参数看起来是正确的.
...which is strange because I am not trying to access the add
action. The params printed below look correct.
这是怎么回事?
仔细看一下stacktrace,错误dosn't occurring in the dispatching process,你似乎认为,它是在你的视图模板中触发的,您可能正在尝试创建指向 add
操作的链接,并且反向路由找不到匹配的路由,因此出现错误.
Take a closer look at the stacktrace, the error dosn't occour in the dispatching process, which you seem to think, it is being triggered in your view template, where you are probably trying to create a link to the add
action, and reverse-routing cannot find a matching route, hence the error.
解决方案应该是显而易见的,连接必要的路由,像
The solution should be obvious, connect the necessary routes, being it explicit ones like
$routes->connect('/screens/add', ['controller' => 'Screens', 'action' => 'add']);
包罗万象
$routes->connect('/screens/:action', ['controller' => 'Screens']);
或者只是捕获一切的后备
or simply the fallback ones that catch everything
$routes->fallbacks('InflectedRoute');
这篇关于CakePHP 3:存在的路由缺少路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!