Answer the question
In order to leave comments, you need to log in
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],
],
],
],
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
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question