I have multiple controllers in my Kohana 3.2 project where the routes where initially:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'user',
'action' => 'index',
));
It was working fine for all my new controllers (when I added a new file and went to: domain/controller it worked like a charm.
Now for a specific controller called parents I had to add new lines in my bootstrap:
Route::set('parents', '(<controller>(/<action>))')
->defaults(array(
'controller' => 'parents',
'action' => 'index',
));
Route::set('parent', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'parent',
'action' => 'index',
));
I was trying to access both: /parents/ and /parent/index/id and both generated an error when not having the Route::set in place.
Without those lines, I always got errors like:
unable to find a route to match the uri
OR
The requested route does not exist
How am I supposed to do it? For every controller that I add do I need to define it in my bootstrap?
Actually you’d be covered with just the default route in your case.
First, Kohana tries to match against your regex pattern [((/(/)))]. This will match the urls: users, users/delete, users/delete/1, parents, parents/view, parents/view/2, etc.
If Kohana is unable to find the action, it will default to index based on your defaults array rule. If Kohana is unable to find a controller (which essentially means nothing passed), then it will use controller. In the last case, it would also default the action since we can’t pass an action without passing a controller in our regex (see the parenthesis requires a controller first then action then id).
So the following examples will route through this default pattern:
Best practice is to keep this route as the last route applied (essentially the default and catch all) and if you have urls that don’t match the pattern in the default, add them.