如何在Kohana 3.3中正确设置路由,其中我的控制器和目录的名称与下面的示例相同?
/application/classes/Controller/Admin/Author.PHP - admin/author - admin/author/add - admin/author/edit /application/classes/Controller/Admin/Author/Book.PHP - admin/author/book - admin/author/book/add - admin/author/book/edit
当按照指定的顺序使用以下路由时,我只能访问admin / author {/ action},而不能访问admin / author / book {/ action}.
通过撤消路由顺序,我可以访问admin / author / book {/ action},但不能访问admin / author {/ action}
Route::set('admin','admin(/<controller>(/<action>(/<id>)))') ->defaults(array( 'directory' => 'admin','controller' => 'Main','action' => 'index',)); Route::set('admin/author','admin/author(/<controller>(/<action>(/<id>)))') ->defaults(array( 'directory' => 'admin/author',));
你需要这样的东西:
Route::set('admin-author','<directory>/<controller>(/<action>(/<id>))',array( 'directory' => '(admin|admin/author)','action' => '(add|edit|delete|index)' )) ->defaults(array( 'directory' => 'admin','controller' => 'author',));
此外,您可以尝试使用regex ^ book(未测试)检查操作.
另一种方法是使用Route filters.