Kohana 3 条路线和路线查询字符串

发布于 2024-10-19 10:35:23 字数 849 浏览 4 评论 0原文

人们普遍认为 Kohana 3 路由机制将忽略查询字符串参数(例如,参见

路由的定义如下:

Route::set('an_action', 'admin/an_action(/<id>)')
->defaults(array(
    'directory'     => 'admin',
    'controller'    => 'welcome',
    'action'        => 'an_action',
));

操作本身需要查询字符串中的“url”参数,如果没有给出,则会出现错误,表明路由成功并且操作尝试执行:

http://myapp.localhost/admin/an_action/3

ERROR: ErrorException [ 8 ]: Undefined index:  url ~ APPPATH/classes/controller/admin/welcome.php [ 37 ]

但是如果我添加 url 查询参数,路由完全失败:

http://myapp.localhost/admin/an_action/3?url=myapp.localhost/admin

Kohana_Request_Exception [ 0 ]: Unable to find a route to match the URI: admin/an_action/3?url=myapp.localhost/admin

更令人沮丧的是,相同的路由设置在我在同一本地主机上开发的另一个应用程序中运行得很好。有想法吗?是我的路线设置不正确吗?难道是 Kohana 安装的问题?预先感谢您的帮助!

It seems to be the general consensus that the Kohana 3 routing mechanism will ignore query string parameters (see, for example this thread). However, this is not the behaviour I'm seeing in my application.

The Route is defined like so:

Route::set('an_action', 'admin/an_action(/<id>)')
->defaults(array(
    'directory'     => 'admin',
    'controller'    => 'welcome',
    'action'        => 'an_action',
));

The action itself requires a "url" parameter from the query string, and an error results if none is given, indicating that routing was successful and the action attempted to execute:

http://myapp.localhost/admin/an_action/3

ERROR: ErrorException [ 8 ]: Undefined index:  url ~ APPPATH/classes/controller/admin/welcome.php [ 37 ]

but if I add the url query parameter, the routing fails altogether:

http://myapp.localhost/admin/an_action/3?url=myapp.localhost/admin

Kohana_Request_Exception [ 0 ]: Unable to find a route to match the URI: admin/an_action/3?url=myapp.localhost/admin

To make it even more frustrating, this same routing setup works just fine in another application I'm developing on the same localhost. Ideas? Is my route not set up properly? Could it be an issue with the Kohana installation? Thanks in advance for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风向决定发型 2024-10-26 10:35:23

嘿!默认的目录是什么?可以去掉吗。

Route::set('an_action', 'admin/an_action(/<id>)')
->defaults(array(
   'controller'    => 'Admin_welcome',
   'action' => 'index'

);

因此,在这种情况下,您将有以下操作:

action: localhost/admin/an_action/3 打开网址
控制器:Controller_admin_welcome,默认操作 - action_index。

因此,如果您希望操作名称出现在 url 中,则需要为该使用 Kohana 保留名称。 - 我不确定这个名字 - 明天我会更新我的帖子。

我相信您已经正确设置了 mod_rewrite 并且 index.php 文件正确。

这是默认控制器:

Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
        'controller' => 'Main',
        'action'     => 'index',
    ));

Hey! What is for directory in the defaults? Can you remove it.

Route::set('an_action', 'admin/an_action(/<id>)')
->defaults(array(
   'controller'    => 'Admin_welcome',
   'action' => 'index'

);

So, in that case you will have following:

action: localhost/admin/an_action/3 to open the url
controller: Controller_admin_welcome with default action - action_index.

So if you want your action name to be in your url you need to use Kohana reserved name for that <action> - I'm not sure about the name - tomorrow I'll update my post for it.

I believe you've setup your mod_rewrite correctly and index.php file correclty.

And this is the default controller:

Route::set('default', '(<controller>(/<action>(/<id>)))')
    ->defaults(array(
        'controller' => 'Main',
        'action'     => 'index',
    ));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文