gpt4 book ai didi

php - Kohana 3.3 Controller 名称和目录名称相同的路由

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:59 25 4
gpt4 key购买 nike

如何在 Kohana 3.3 中正确设置路由,其中​​我的 Controller 和目录的名称与下面的示例相同?

/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

When using the following routes in the specified order, I'm only able to access admin/author{/action}, but not admin/author/book{/action}.

Reversing the routing order gives me access to admin/author/book{/action}, but not 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',
'controller' => 'Main',
'action' => 'index',
));

最佳答案

你需要这样的东西:

Route::set('admin-author', '<directory>/<controller>(/<action>(/<id>))', array(
'directory' => '(admin|admin/author)',
'action' => '(add|edit|delete|index)'
))
->defaults(array(
'directory' => 'admin',
'controller' => 'author',
));

此外,您可以尝试使用正则表达式 ^book(未测试)检查操作。

另一种方法是使用 Route filters .

关于php - Kohana 3.3 Controller 名称和目录名称相同的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com