Kohana 3 条路线和路线查询字符串
人们普遍认为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿!默认的目录是什么?可以去掉吗。
);
因此,在这种情况下,您将有以下操作:
action: localhost/admin/an_action/3 打开网址
控制器:Controller_admin_welcome,默认操作 - action_index。
因此,如果您希望操作名称出现在 url 中,则需要为该使用 Kohana 保留名称。 - 我不确定这个名字 - 明天我会更新我的帖子。
我相信您已经正确设置了 mod_rewrite 并且 index.php 文件正确。
这是默认控制器:
Hey! What is for directory in the defaults? Can you remove it.
);
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: