Reputation: 1120
Route::set('category', 'category/date/<id>(/<year>)', array('id' => '[0-9]+', 'year' => '[0-9]+'))
->defaults(array(
'controller' => 'category',
'action' => 'date',
));
Is there any cap for parameters on a kohana 3.2 route?
I've implemented this route in my bootstrap but everytime I try to pass the year
value I get a 404 error!
Passing of the ID alone just works fine.
Am i missing anything?
This is the controller action for handling this route:
public function action_date() {
$id = $this->request->param('id');
$year = $this->request->param('year');
if(!isset($year) && $year == ""){
$year = date("Y", time());
}
//Do fancy stuff here... and hand it to the view!
}
Upvotes: 0
Views: 452
Reputation: 1895
Kohana should route that to the right action, and it does for me. My guess is that you either overwrite that route with one also named 'category' or it gets matched by another route which action throws a Kohana_Exception_404.
You should be able to dissmiss/verify if a Kohana_Exception_404 is thrown from a method by looking at the stack trace.
Route names are used as key names for the array in which the routes are stored as can be seen below. Using the same name twice would overwrite the previous route which was under that name.
public static function set($name, $uri_callback = NULL, $regex = NULL)
{
return Route::$_routes[$name] = new Route($uri_callback, $regex);
}
You could use the following in a action somewhere to see all the routes used for routing: $this->response->body(Debug::vars(Route::all()));
Then you are able to check the compiled regex of the 'category' route or similar.
Upvotes: 1
Reputation: 503
Try making non-optional (remove the brackets) and see if it works then. Also, it seems like there's a logic bug in your code. In your original code, $year will always be set so the if statement is always skipped. Try replacing the if statement and the the line before it with:
$year = $this->request->param('year', date('Y'));
Oh and as a brucey bonus, date() defaults to the current timestamp so the extra call to time() isn't needed. Hope that works for you now.
Upvotes: 0
Reputation: 3257
No, there's no limit. Make sure this route is above your default route (or delete the default all together).
Upvotes: 2