我正在使用yii2基本模板。我試圖創建使用yii2數據庫遷移RBAC DB,我已經創建了幾張桌子成功,雖然我創建RBAC表我有不同的功能,如下所示:組件不是在yii2基礎上獲取加載的組件
protected function getAuthManager()
{
$authManager = Yii::$app->getAuthManager();
if (!$authManager instanceof DbManager) {
throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.');
}
return $authManager;
}
此功能沒有返回authManager即使我已經加入此
'authManager'=>[
'class'=>'yii\rbac\DbManager',
],`
錯誤的console.php
前幾行
是:
Exception: You should configure "authManager" component to use database before executing this migration. (C:\xampp\htdocs\PMTool\migrations\m150820_064854_rbac.php:13)
C:\xampp\htdocs\PMTool\migrations\m150820_064854_rbac.php(20): m150820_064854_rbac->getAuthManager()
console.php的
代碼
`<?php
Yii::setAlias('@tests', dirname(__DIR__) . '/tests');
$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
return [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log', 'gii'],
'controllerNamespace' => 'app\commands',
'modules' => [
'gii' => 'yii\gii\Module',
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'authManager'=>[
'class'=>'yii\rbac\DbManager',
],
],
'params' => $params,
];
可以肯定的是:你是否在''components''下添加了它?不可能在這裏看到。 (雖然我懷疑'Yii'不會啓動,如果你將它添加到其他地方) – Blizz
''authManager'=> [ 'class'=>'yii \ rbac \ DbManager', ],'add in'web.php '文件,'componets'數組的一部分。 – GAMITG
是的,我已經將它添加到組件@Blizz – akhil