eme*_*his 10 php cakephp cakephp-3.0
CakePHP 3.0
对于存在的路径,我收到"丢失路由"错误.
这是我的路线:
#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();
Run Code Online (Sandbox Code Playgroud)
基本上我只是将顶部(用于管理路由)添加到开箱即用的默认路由中.
当我访问时,/admin/screens/index我看到以下错误:

请注意错误消息说:
错误:路由匹配"array('action'=>'add','prefix'=>'admin','plugin'=> NULL,'controller'=>'Screens','_ ext'=> NULL,) "找不到.
...这很奇怪,因为我没有尝试访问该add操作.下面打印的参数看起来是正确的.
到底是怎么回事?
ndm*_*ndm 14
仔细查看堆栈跟踪,调度过程中的错误不会出现,您似乎认为,它在您的视图模板中被触发,您可能正在尝试创建指向该add操作的链接,并且反向 -路由找不到匹配的路由,因而错误.
解决方案应该是显而易见的,连接必要的路线,就像明确的那样
$routes->connect('/screens/add', ['controller' => 'Screens', 'action' => 'add']);
Run Code Online (Sandbox Code Playgroud)
抓住所有人
$routes->connect('/screens/:action', ['controller' => 'Screens']);
Run Code Online (Sandbox Code Playgroud)
或者只是那些能够抓住一切的后备者
$routes->fallbacks('InflectedRoute');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6612 次 |
| 最近记录: |