我試圖將cakephp 2.x轉換爲3.x.我正在使用Router::connect()
規則,但我嘗試將它們轉換爲範圍版本。CakePHP 3路由與語言參數
關於myold路由規則,在config/routes.php
我加了這個。
Router::defaultRouteClass('Route');
Router::scope('/', function ($routes) {
$routes->connect('/:language/:controller/:action/*', ['language' => 'ar|de|en|fr']);
$routes->connect('/:language/:controller', ['action' => 'index', 'language' => 'ar|de|en|fr']);
$routes->connect('/:language', ['controller' => 'Mydefault', 'action' => 'index', 'language' => 'ar|de|en|fr']);
$routes->redirect('/gohere/*', ['controller' => 'Mycontroller', 'action' => 'myaction'], ['persist' => array('username')]);
$routes->connect('/', ['controller' => 'Mydefault', 'action' => 'index']);
$routes->fallbacks('InflectedRoute');
});
- 但這種失敗在
example.com/en/works
。我得到這個錯誤:Error: worksController could not be found.
因爲我的控制器文件是WorksController.php
。
控制器名稱部分是否被判處casein cakephp 3? http://book.cakephp.org/3.0/en/intro/conventions.html#controller-conventions
- 也
example.com/foo/bar
給出了這樣的錯誤:Error: barController could not be found.
。但foo
是控制器,bar
是行動。
我該如何解決這個路由問題?
編輯:
更改Route::defaultRouteClass('Route')
爲Route::defaultRouteClass('InflectedRoute')
解決了問題1.但存在問題2。
必須有一條線'路線:: defaultRouteClass( 'Route')'在你的routes.php的頂部。將其更改爲'Route :: defaultRouteClass('InflectedRoute')'。 – ADmad
此固定錯誤1.但存在錯誤2。當我輸入'example.com/foo/bar'時,cakephp會查找barController。 – trante