Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Owner 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