在Controller的Init方法里无法获得当前Action

在controller的init方法里无法获得当前action,请问应该怎样解决?

init() is called before the action is determined, so you cannot reliably get the current action there. Use beforeAction($action) instead:

protected function beforeAction($action)
{
    // $action->id
    return parent::beforeAction($action);
}

This gives you access to the current action before it executes.