我可以在Kohana 3中的控制器的before()方法中获取操作吗?

时间:2011-01-31 03:32:23

标签: php kohana

我的控制器有......

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);
    }

}

我的路线是......

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

当我输入调用bla/get/42的网址(Controller_Staff->before())时(在致电action_get()之前),我可以访问$id中的before(),但是{{ 1}}总是$action

是否有更好的方式来访问NULL方法中的当前$action

感谢。

1 个答案:

答案 0 :(得分:2)

发现它!

最终非常很容易。

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