问题描述
cakephp 3.0
cakephp 3.0
对于存在的路线,我收到了缺少路线"的错误消息.
i'm getting a "missing route" error for a route that exists.
这是我的路线:
#my ***** routes... router::prefix('*****', 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 ***** routing) to the default routes that come out of the box.
当我访问 /*****/screens/index 时,我看到以下错误:
when i visit /*****/screens/index i see the following error:
注意错误信息说:
错误:匹配array ('action' => 'add', 'prefix' =>'*****', 'plugin' => null, 'controller' => 'screens', '_ext' => null,)"无法找到.
error: a route matching "array ( 'action' => 'add', 'prefix' => '*****', '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.
百家乐凯发k8的解决方案应该是显而易见的,连接必要的路由,像
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');