Kohana 3 Routes & Query Strings
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 开发者_JAVA技巧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!
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',
));
精彩评论