我的网站在 Kohana 3.0 下,与默认路由完美配合
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'user',
'action' => 'index',
));
当我尝试在此地址访问我的网站时,http://127.0.0.1/web/
它会加载 url http://127.0.0.1/web/user
。没关系。但是现在我想在控制器下添加管理目录。所以我的网络树看起来像这样
classes
| controller/
Admin/
dashboard
web.php
| model
我想允许管理员以这样的 url 访问管理员页面
http://127.0.0.1/admin/dashboard
。其中dashboard是管理员目录下的控制器。我用这个修改引导文件
Route::set('admin', '<directory>(/<controller>(/<action>(/<id>)))',
array('directory' => '(admin)'))->defaults(array(
'controller' => 'user',
'action' => 'index',
));
我可以通过访问管理会话http://127.0.0.1/web/admin/dashboard/
但我无法访问默认控制器,即http://127.0.0.1/web/
. 错误Kohana_Request_Exception [ 0 ]: Unable to find a route to match the URI:
我缺少控制器的默认访问权限。如何设置 Route 它以通过链接访问我的网站:
http://127.0.0.1/web/
和
http://127.0.0.1/web/admin/dashboard/
编辑 从kohana文档中,它被写成
In this example, we have controllers in two directories, admin and affiliate. Because this route will only match urls that begin with admin or affiliate, the default route would still work for controllers in classes/controller.
Route::set('sections', '<directory>(/<controller>(/<action>(/<id>)))',
array(
'directory' => '(admin|affiliate)'
))
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
资源 :http://kohanaframework.org/3.0/guide/kohana/routing#examples
现在我将我的代码修改为
Route::set('default', '<directory>(/<controller>(/<action>(/<id>)))',
array(
'directory' => '(admin)'))
->defaults(array(
'controller' => 'user',
'action' => 'index',
));
但我有这个错误
Kohana_Request_Exception [ 0 ]: Unable to find a route to match the URI:
当我想访问默认控制器时http://127.0.0.1/user/index