/gist:7b2db1abbf22b4cd74b2 Secret
Created
July 30, 2010 18:32
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::set('testing', function($uri) | |
{ | |
if ($uri == 'foo/bar') | |
return array( | |
'controller' => 'welcome', | |
'action' => 'foobar', | |
); | |
} | |
); | |
Route::set('testing', function($uri) | |
{ | |
if ($uri == '</language regex/>(.+)') | |
{ | |
Cookie::set('language', $match[1]); | |
return array( | |
'controller' => 'welcome', | |
'action' => 'foobar' | |
); | |
} | |
} | |
); |
If the route should not match, you should simple not return anything.
The relevant code in core is this: http://github.com/kohana/core/blob/feature/3090-new-routing/classes/kohana/request.php#L681-L718
It will awk and grep the parameters that you return, and infer some other ones. I'm not sure defaults make sense with callback/lambda routes. The "defaults" would be integrated into your processing logic. In this case, 'welcome/foobar' is the default, if that makes sense. Yes that means this route could be specified the old way, but this is meant to me a simple proof of concept.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
love it. would you simply not return anything or FALSE if you decide the $uri should not match?
also, how would I specify that the uri matches but I want to use the defaults?