phprouteskohana-3kohana-2

Routing differences between Kohana v2 and v3


In Kohana 2, a controller function could have arguments in it without needing to write a route for it.

url: /some/arg/is/here

and in the controller, i could simply have four args, of any name, and they'd be automatically accessible from within the function.

public function myFunc($a, $b, $c, $d) {}

but in Kohana 3, I have to go write a route for type of route I want to have. Is there a route I can use that will make my url and args play nice with each other without me having to do extra work each time i write a new function?


Solution

  • All args must be specified in the route, but can be made optional. In this instance you may want to change the default route to something like...

    Route::set('default', '(<controller>(/<action>(/<arg1>(/<arg2>(/<arg3>(/<arg4>))))))');
    

    You can then reference the args by using "request"...

    $this->request->param('arg1');
    $this->request->param('arg2');
    $this->request->param('arg3');
    $this->request->param('arg4');
    

    You could obviously have more than 4 if you needed them.