Kohana 3 Routing and Query Strings
If I have a route like this:
Route::set('test', 'test')
->defaults(array(
'controller' => 'test',
'action' => 'index'
));
I assumed that only the url mysite.com/test or mysite.com/test/ would be sent to this route and anything else would be sent to the default route, or a catch all route if you have one. However, you can tack on any query strings and it will still be valid. For example any of these would work:
mysite.com/test/?abc
mysite.com/test/?abc=123
mysite.com/test/?abc=123&blabla=lala
Anything you want basically. How can I set it so that the test route doesn't match the URL with query strings? Another example might be this:
Route::set('test', 'test(/?order=<order>)', array('order' => 'title|date|author'))
->defaults(array(
'controller' => 'test',
'action' => 'index'
'order' => 'title'
));
In this example, I would assume the only URLs to match this route would be:
mysite.com/test/?order=title
mysite.com/test/?order=date
mysite.com/test/?order=author
But like before, you can just add on any other query string you want.
Is there any way to have these invalid query st开发者_如何学Gorings pass to the catch all route where they will be sent to a 404 page? Or do I literally have to go through all my controllers and perform a check on the $_GET and make sure they actually exist?
You're not supposed to access query parameters using your routes.
Routes are totally isolated from the query string, don't try to use them as you'd use mod_rewrite. To access query params you should use:
$order = $this->request->query('order');
精彩评论