Dedikisme's Blog

Ngeblog biar dibilang eksis

Rbac DBManager Yii2 Migration Table

Sebenernya ini lanjutan dari artikel 2 bulan yang lalu mengenai Rbac Yii2 Menggunakan DBManager. Kalo gak salah linknya yang ini http://blog.dedikisme.com/blog/2014/05/10/rbac-yii2-authmanager/ untuk menggunkan Rbac DBmanager yang harus dilakukan membuat table – table yang dibutuhkan. caranya dengan eksekusi perintah berikut

1
yii migrate --migrationPath=vendor/yiisoft/yii2/rbac/migrations

jika berhasil akan muncul notifikasi seperti ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Yii Migration Tool (based on Yii v2.0.0-dev)

Total 1 new migration to be applied:
    m140506_102106_rbac_init

Apply the above migration? (yes|no) [no]:yes
*** applying m140506_102106_rbac_init
    > create table  ... done (time: 0.341s)
    > create table  ... done (time: 0.212s)
    > create index idx-auth_item-type on  (type) ... done (time: 0.328s)
    > create table  ... done (time: 0.262s)
    > create table  ... done (time: 0.201s)
*** applied m140506_102106_rbac_init (time: 1.427s)


Migrated up successfully.

dan jika terdapat error seperti

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: yii\console\Request::cookieValidationKey'

in /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Component.php:197

Stack trace:
#0 /var/www/html/yii2shop/vendor/yiisoft/yii2/BaseYii.php(518): yii\base\Component->__set('cookieValidatio...', 'thisIsAKey')
#1 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Object.php(105): yii\BaseYii::configure(Object(yii\console\Request), Array)
#2 [internal function]: yii\base\Object->__construct(Array)
#3 /var/www/html/yii2shop/vendor/yiisoft/yii2/di/Container.php(364): ReflectionClass->newInstanceArgs(Array)
#4 /var/www/html/yii2shop/vendor/yiisoft/yii2/di/Container.php(147): yii\di\Container->build('yii\console\Req...', Array, Array)
#5 /var/www/html/yii2shop/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('yii\console\Req...', Array, Array)
#6 /var/www/html/yii2shop/vendor/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::createObject(Array)
#7 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Application.php(530): yii\di\ServiceLocator->get('request')
#8 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Application.php(371): yii\base\Application->getRequest()
#9 /var/www/html/yii2shop/yii(30): yii\base\Application->run()
#10 {main}
PHP Warning:  array_map(): An error occurred while invoking the map callback in /var/www/html/yii2shop/vendor/yiisoft/yii2/log/FileTarget.php on line 99

maka coba membypass request cookies validationnya

main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'extensions' => require(__DIR__ . '/../../vendor/yiisoft/extensions.php'),
    'components' => [
//        'request' => [
//            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
//            'cookieValidationKey' => 'thisIsAKey',
//        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
         'authManager' => [
            'class' => 'yii\rbac\DbManager',
        ],
    ],
];

jika sudah berhasil aktifkan kembali cookie validationnya dan jika terdapat error seperti

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Yii Migration Tool (based on Yii v2.0.0-dev)

Total 1 new migration to be applied:
    m140506_102106_rbac_init

Apply the above migration? (yes|no) [no]:y
*** applying m140506_102106_rbac_init
Exception 'yii\base\InvalidConfigException' with message 'You should configure "authManager" component to use database before executing this migration.'

in /var/www/html/yii2shop/vendor/yiisoft/yii2/rbac/migrations/m140506_102106_rbac_init.php:28

Stack trace:
#0 /var/www/html/yii2shop/vendor/yiisoft/yii2/rbac/migrations/m140506_102106_rbac_init.php(35): m140506_102106_rbac_init->getAuthManager()
#1 /var/www/html/yii2shop/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(488): m140506_102106_rbac_init->up()
#2 /var/www/html/yii2shop/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(126): yii\console\controllers\BaseMigrateController->migrateUp('m140506_102106_...')
#3 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#4 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#5 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Controller.php(150): yii\base\InlineAction->runWithParams(Array)
#6 /var/www/html/yii2shop/vendor/yiisoft/yii2/console/Controller.php(88): yii\base\Controller->runAction('', Array)
#7 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Module.php(462): yii\console\Controller->runAction('', Array)
#8 /var/www/html/yii2shop/vendor/yiisoft/yii2/console/Application.php(161): yii\base\Module->runAction('migrate', Array)
#9 /var/www/html/yii2shop/vendor/yiisoft/yii2/console/Application.php(137): yii\console\Application->runAction('migrate', Array)
#10 /var/www/html/yii2shop/vendor/yiisoft/yii2/base/Application.php(371): yii\console\Application->handleRequest(Object(yii\console\Request))
#11 /var/www/html/yii2shop/yii(30): yii\base\Application->run()
#12 {main}

coba untuk menset ‘authManager’nya pada config main.php seperti config main.php diatas

Comments