khairil
khairil

Reputation: 319

kohana 3 routing problem with controller action parameter

I have this routing defined in my module's init.php;


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

and the default route in bootstrap.php is still intact.


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

my Controller_Item class;


class Controller_Item extends Controller {
    function action_category($category_id)
    {
        echo 'Category ID: '.$category_id;
    }
}

Using http://mydomain.com/item/category/8
Output:

Category ID: 8
they point to correct routing which was;
Controller_Item and method action_category(8)

The problem is when using modified route; http://mydomain.com/store/1/item/category/8 Output:

Category ID: 1
it become action_category(1) (it takes the parameter from <store_id>)

Upvotes: 0

Views: 1322

Answers (1)

biakaveron
biakaveron

Reputation: 5483

Get param by name:

$id = $this->request->param('id');

Upvotes: 2

Related Questions