Yii 2用户认证&基于角色的访问控制(RBAC)模块安装和使用

时间:2014-04-05 12:18:23

标签: php rbac yii2

我正在尝试在新安装的yii2高级应用中安装和使用此 robregonm / yii2-auth模块。 我用composer来安装它。 使用此命令

php composer.phar require robregonm/yii2-auth "dev-master"

我已相应地配置了我的网络和控制台文件。 现在我正在尝试使用

提到的迁移
./yii migrate/up --migrationPath=@auth/migrations

我收到了以下错误。

Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\db\Connection::user'

in /var/www/mycoolapp/vendor/yiisoft/yii2/base/Component.php:196

Stack trace:
#0 /var/www/mycoolapp/vendor/yiisoft/yii2/BaseYii.php(515): yii\base\Component->__set('user', Array)
#1 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Object.php(104): yii\BaseYii::configure(Object(yii\db\Connection), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 /var/www/mycoolapp/vendor/yiisoft/yii2/di/Container.php(365): ReflectionClass->newInstanceArgs(Array)
#4 /var/www/mycoolapp/vendor/yiisoft/yii2/di/Container.php(147): yii\di\Container->build('yii\db\Connecti...', Array, Array)
#5 /var/www/mycoolapp/vendor/yiisoft/yii2/BaseYii.php(341): yii\di\Container->get('yii\db\Connecti...', Array, Array)
#6 /var/www/mycoolapp/vendor/yiisoft/yii2/di/ServiceLocator.php(132): yii\BaseYii::createObject(Array)
#7 /var/www/mycoolapp/vendor/yiisoft/yii2/console/controllers/MigrateController.php(124): yii\di\ServiceLocator->get('db')
#8 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Controller.php(144): yii\console\controllers\MigrateController->beforeAction(Object(yii\base\InlineAction))
#9 /var/www/mycoolapp/vendor/yiisoft/yii2/console/Controller.php(83): yii\base\Controller->runAction('up', Array)
#10 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Module.php(444): yii\console\Controller->runAction('up', Array)
#11 /var/www/mycoolapp/vendor/yiisoft/yii2/console/Application.php(164): yii\base\Module->runAction('migrate/up', Array)
#12 /var/www/mycoolapp/vendor/yiisoft/yii2/console/Application.php(140): yii\console\Application->runAction('migrate/up', Array)
#13 /var/www/mycoolapp/vendor/yiisoft/yii2/base/Application.php(329): yii\console\Application->handleRequest(Object(yii\console\Request))
#14 /var/www/mycoolapp/yii(30): yii\base\Application->run()
#15 {main}
PHP Fatal error:  Uncaught exception 'yii\base\InvalidConfigException' with message 'Unable to append to log file: /var/www/mycoolapp/console/runtime/logs/app.log' in /var/www/mycoolapp/vendor/yiisoft/yii2/log/FileTarget.php:87
Stack trace:
#0 /var/www/mycoolapp/vendor/yiisoft/yii2/log/Target.php(103): yii\log\FileTarget->export()
#1 /var/www/mycoolapp/vendor/yiisoft/yii2/log/Dispatcher.php(179): yii\log\Target->collect(Array, true)
#2 /var/www/mycoolapp/vendor/yiisoft/yii2/log/Logger.php(162): yii\log\Dispatcher->dispatch(Array, true)
#3 [internal function]: yii\log\Logger->flush(true)
#4 {main}
  thrown in /var/www/mycoolapp/vendor/yiisoft/yii2/log/FileTarget.php on line 87

我很困惑这里遗失的是什么? 我无法在app中的任何地方找到auth模块。 我的问题是我应该在哪里克隆应用程序中的yii2-auth?

2 个答案:

答案 0 :(得分:2)

更改您的console / config / main-local.php,将键 preload 替换为 bootstrap

return [
    'preload' => [
        //'debug',
    ],
    'modules' => [
        //'debug' => 'yii\debug\Module',
        //'gii' => 'yii\gii\Module',
    ],
];

return [
    'bootstrap' => [
        //'debug',
    ],
    'modules' => [
        //'debug' => 'yii\debug\Module',
        //'gii' => 'yii\gii\Module',
    ],
];

答案 1 :(得分:1)

您的配置文件中似乎错误配置了db组件,因为user参数不存在,可能您的意思是username。所以问题不在于扩展本身,而在于您的本地配置设置。

您的db组件应如下所示:

    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'pgsql:dbname=YourDbName...', // replace pgsql with your db driver
        'username' => 'YourUsername',
        'password' => 'YourPwd',
        'enableSchemaCache' => false,
        'charset' => 'utf8',
    ],

希望这有帮助。