0

searching for this question, I found this question/answer: Kohana 3 get current controller/action/arguments

I recently switched to Kohana after using codeigniter for a while. In Codeigniter, you could just do (in a Controller):

public function action_nameAction($param1, $param2 = null, ...){
$something = $param1;
}

by calling www.mysite.com/controllerName/param1/param2

I really liked this approach and don't really understand the point of Kohana's approach with redefining the routes...

If there is a solution to have the Codeigniter approach in Kohana, I would like some clues on how to implement it. If not, please could someone explain me the interest of having to redefine new routes for every case that doesnt fall into the default route...

Community
  • 1
  • 1
Pierre
  • 4,976
  • 12
  • 54
  • 76

1 Answers1

1
Route::set('default', '(<controller>(/<action>(/<id1>(/<id2>))))')
    ->defaults(array(
    'controller' => 'welcome',
    'action' => 'index',
));

$id = $request->param('id1');
$id = $request->param('id2');
stormdrain
  • 7,915
  • 4
  • 37
  • 76
  • Thanks for your answer, but I already know that, this is not what I was asking for... – Pierre Oct 24 '11 at 10:42
  • You said: "If there is a solution to have the Codeigniter approach in Kohana, I would like some clues on how to implement it". I gave you an answer to set up Kohana so it behaves like CI. If you want to change the way Kohana works with routing altogether, you should just use CI because it would probably mean re-writing Kohana's core. – stormdrain Oct 24 '11 at 13:21
  • I said that I would like to have the uri's parameters in the controller's function's parameters, like in CI. I didn't ask about the uri. Sorry if it wasn't clear. And I didn't ask you to tell me what I should do or not, I was just wondering what was the logic behind Kohana's route system. – Pierre Oct 24 '11 at 16:24
  • 3
    Oh, ok. I'm not sure why Kohana chose that way. Likely to make things modular/customizable. I don't understand, though, why does it matter if the params are available as function params if they are available in the example I put. It behaves the same way essentially. And I didn't mean to sound like I was telling you what you should do but rather that the way their routing is set up, it's likely heavily integrated into the rest of the framework and would be a LOT of work to change. If you're starting off on a new project it just seems easier to use CI if you must have params in the functions. – stormdrain Oct 24 '11 at 17:12