user1391445
user1391445

Reputation: 731

Kohana routing: can't access route parameters

In Kohana 3.2 I'm using the default route for a simple controller/action/id setup:

Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
    'controller' => 'home',
    'action'     => 'index',
    'id'         => '0',
));

Per the documentation it's pretty easy to wire up controllers and actions to a simple route like this, but route parameters (in this case id) are never accessible in the controllers.

So for example I have a route:

/user/info/123

And the controller handling that route gets called successfully:

    public function action_info()
{
    $id = $this->request->param('id');
    echo "id=" . $id; //nothing
    echo "is_null=" . is_null($this->request->param('id')); //1
}

But $this->request->param('id') is always set to null.

This seems like about the simplest example I can come up with, what could I be doing wrong here?

Upvotes: 1

Views: 318

Answers (2)

user1391445
user1391445

Reputation: 731

Turns out the company I'm working with extended Kohana with a request->param() function to do something without realizing that was already a function in Kohana, and this broke the built in functionality. Using the built in Kohana request function fixes this problem.

So this turns out to be a non-question as this is the correct way to get request parameters after all. :)

Upvotes: 2

Tuan
Tuan

Reputation: 1486

Have you tried this?

Route::set('default', '(<controller>(/<action>(/<id>)))')
  ->defaults(array(
    'controller' => 'home',
    'action'     => 'index',
    'id'         => '\d+',
));

Upvotes: 1

Related Questions