【发布时间】:2012-12-11 15:52:58
【问题描述】:
我的网站在 Kohana 3.0 下,与默认路由完美配合
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'user',
'action' => 'index',
));
当我尝试在此地址 http://127.0.0.1/web/ 访问我的网站时,它会加载网址 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这样的默认控制器时
【问题讨论】:
-
“web”文件夹不存在。它必须是
http://127.0.0.1/admin/web。使用该路由器,您的目录不是可选的 -
我弄错了它是127.0.0.1/user/index
-
然后用正确的代码编辑你的答案,因为我不知道你在谈论用户或管理员
-
建议您使用多条路线,而不是尝试使用通用的包罗万象的路线来解决您的问题。
-
是的,它适用于多条路线。谢谢