Skip to content

Instantly share code, notes, and snippets.

@zombor
Created July 30, 2010 18:32
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zombor/7b2db1abbf22b4cd74b2 to your computer and use it in GitHub Desktop.
<?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'
);
}
}
);
@zeelot
Copy link

zeelot commented Jul 30, 2010

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?

@zombor
Copy link
Author

zombor commented Jul 30, 2010

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