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

问题描述 投票:0回答:1

我的控制器有...

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
的 URL (
Controller_Staff->before()
)(在调用
action_get()
之前)时,我可以在
$id
中访问
before()
,但
$action
始终是
NULL

有没有更好的方法在

$action
方法中访问当前的
before()

php kohana
1个回答
2
投票

找到了!

最终变得非常容易。

$action = $this->request->action;
© www.soinside.com 2019 - 2024. All rights reserved.