Doubts about Yii2 RBAC

后端 未结 5 2047
情歌与酒
情歌与酒 2021-02-20 07:50

I\'ve been developing web apps using Yii 1.1.14 so far, but now it\'s time for an upgrade.

The company where I work has developed its own Access Control system, and I wa

5条回答
  •  半阙折子戏
    2021-02-20 08:03

    This is the best solution i could come up with when facing the need to filter access by permissions, it's bothersome but can be useful if you're trying to create roles in a productive enviroment and want to use rbac.

    use yii\web\ForbiddenHttpException;
    
    
    if(Yii::$app->user->can('view-users')){
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }else{
        throw new ForbiddenHttpException('You dont have access to this site');
    }
    

提交回复
热议问题