加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php – Kohana 3.3控制器和目录名称相同的路由

发布时间:2020-05-25 09:07:59 所属栏目:PHP 来源:互联网
导读:如何在Kohana 3.3中正确设置路由,其中我的控制器和目录的名称与下面的示例相同? /application/classes/Controller/Admin/Author.php - admin/author - admin/author/add - admin/author/edit/application/classes/Controller/Admin/Author/B

如何在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.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读