【发布时间】:2015-08-20 07:40:51
【问题描述】:
我正在使用 yii2 基本模板。我正在尝试使用 yii2 中的数据库迁移创建 RBAC DB,我已经成功创建了几个表,并且在创建 RBAC 表时,我得到了不同的功能,如下所示:
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',
],`
在控制台.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如果你在其他地方添加它就不会启动) -
'authManager'=>[ 'class'=>'yii\rbac\DbManager', ],添加web.php文件,componets数组的部分。 -
是的,我已经在组件@Blizz 下添加了它
-
我已经在 web.php 和 console.php 中添加了它,但实际上我正在控制台中进行迁移,所以我认为在 web.php 中添加它不会对解决这个问题产生影响。@游戏
-
@akhil 你是对的
web.php评论没有解决任何问题
标签: yii2 yii-components