问题描述
CakePHP 3.0
CakePHP 3.0
我收到一条路径存在的Missing Route错误。
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:
>
注意错误信息:
...这很奇怪,因为我没有尝试访问 add
操作。
...which is strange because I am not trying to access the add
action. The params printed below look correct.
发生了什么事情?
推荐答案
p>仔细看看stacktrace,错误dosn't occour在调度过程,你似乎认为,它是在你的视图模板中触发,你可能试图创建一个链接到 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:缺少存在的路由的路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!