Search code examples
phpkohana

Can I get the action in the before() method of a controller in Kohana 3?


My controller has...

class Controller_Staff extends Controller {

    public function before() {
       parent::before();
       $id = $this->request->param('id');
       $action = $this->request->param('action');
    }
    
    public function action_get($id) {
       var_dump($id);
    }

}

My route is...

Route::set('a', 'bla/<action>/<id>',
            array('id' => '\d+', 'action' => '(get|set)'))
    ->defaults(array(
        'controller' => 'staff',
        'action' => 'set'
    ));

When I enter a URL (bla/get/42) which calls Controller_Staff->before() (before calling action_get()), I can access $id in before(), but $action is always NULL.

Is there a better way to access the current $action in the before() method?


Solution

  • Found it!

    It ended up being very easy.

    $action = $this->request->action;