J
J
Julia Kovalenko2016-04-14 16:34:02
Yii
Julia Kovalenko, 2016-04-14 16:34:02

RBAC in Yii2: Exeption is displayed as plain text, without decoration. How to fix?

Made rbac according to this article https://habrahabr.ru/post/235485/.
There are 2 ways to check access.
When I do it in the 1st way: at the beginning of each action I write

if (!\Yii::$app->user->can('about')) {
        throw new ForbiddenHttpException('Access denied');

then everything is rendered via site/error.
And when I do it in the 2nd way (in beforeAction), the exception is displayed in plain text.
public function beforeAction($action)
{
    if (parent::beforeAction($action)) {
        if (!\Yii::$app->user->can($action->id)) {
            throw new ForbiddenHttpException('Access denied');
        }
        return true;
    } else {
        return false;
    }
}

How to render an error in beforeAction?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-04-14
@kovalenko_jul_s

In your rules, apparently, the user cannot site / error.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question