M
M
Mark2020-01-18 16:47:48
Yii
Mark, 2020-01-18 16:47:48

How to solve "Uncaught Error" error in Yii2 Basic configurations?

Implemented access sharing in the application. Pasted the configuration into the "components" section of the settings:

'as access' => [
            'class' => 'yii\filters\AccessControl',
            'except' => ['auth/login', 'site/error'],
            'rules' => [
                [
                    'allow' => true,
                    'roles' => [\app\rbac\Roles::ROLE_ADMIN],
                ],
            ],
        ],

But I am getting the following error:
Fatal error: Uncaught Error: Class 'app\rbac\Roles' not found in D:\OSPanel\domains\work\work24.loc\config\web.php:89 Stack trace: #0 D:\OSPanel\domains\work \work24.loc\web\index.php(10): require() #1 {main} thrown in D:\OSPanel\domains\work\work24.loc\config\web.php on line 89

Moreover, I have been using this configuration for a long time in Basic / Advanced, but this time something went wrong. I checked the paths, the correctness of the input, several settings - it did not help.
Optionally - the Roles class

namespace app\rbac;


class Roles
{
    const ROLE_ADMIN = 'admin';

    public static function hasRole($roleName, $userId)
    {
        $userRoles = \Yii::$app->authManager->getRolesByUser($userId);

        foreach ($userRoles as $userRole) {
            if ($userRole->name == $roleName) {
                return true;
            }
        }

        return false;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2020-01-18
@Arik

?
composer dumpautoload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question