YII2带模块的访问控制

时间:2015-06-02 08:40:47

标签: yii2 access-control

我的访问控制代码不在模块默认控制器上工作,但在所有其他页面上工作正常。知道我做错了吗?

编辑:发生的事情是:../ web / mymodule不重定向但是../web/mymodule/mycontroller。此外,如果尝试../web/mymodule/default它也不起作用。

编辑2:解决了。问题在于public function beforeAction($action)

public function behaviors()
{
    return [
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'delete' => ['post'],
            ],
        ],
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
    ];
}

1 个答案:

答案 0 :(得分:0)

似乎你无法控制行动。请在SiteController中尝试此操作:

    return [
        'access' => [
            'class' => AccessControl::className(),
            'only' => ['logout', 'signup'],
            'rules' => [
                [
                    'actions' => ['signup'],
                    'allow' => true,
                    'roles' => ['?'],
                ],
                [
                    'actions' => ['logout'],
                    'allow' => true,
                    'roles' => ['@'],
                ],
            ],
        ],
        ],
        'verbs' => [
            ..............
        ],
    ];