Closed xCEZAREx closed 6 years ago
It's expected since there are no cookies in console.
@samdark : could you help to enlighten us how to make it work? I've run into similar cases, but with rbac. Has been reading and following the instructions how to set rbac to the letter (https://www.yiiframework.com/doc/guide/2.0/en/security-authorization).
Failed at ./yii rbac/init with message:
Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\console\Request::validateCsrfToken()'
Please show stacktrace for the error.
@samdark: this is the stack trace.
Stack trace:
#0 [internal function]: yii\BaseYii::autoload('console\\control...')
#1 [internal function]: spl_autoload_call('console\\control...')
#2 /home/workspace/php/toko/vendor/yiisoft/yii2/base/Module.php(637): class_exists('console\\control...')
#3 /home/workspace/php/toko/vendor/yiisoft/yii2/base/Module.php(596): yii\base\Module->createControllerByID('rbac')
#4 /home/workspace/php/toko/vendor/yiisoft/yii2/base/Module.php(522): yii\base\Module->createController('init')
#5 /home/workspace/php/toko/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('rbac/init', Array)
#6 /home/workspace/php/toko/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('rbac/init', Array)
#7 /home/workspace/php/toko/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#8 /home/workspace/php/toko/yii(27): yii\base\Application->run()
#9 {main}
Tried it twice, at my current project, and a new yii2 advanced (composer). Set the database, copy the RbacController.php
to console/controllers
then run ./yii rbac/init
. The code runs fine if I put it on backend/controllers
and run it from browser. The code has nothing fancy. Just copy-paste from yii 2.0 doc guide stated before.
Thanks!
on console/config/main.php
include the follwoing line
'bootstrap' => new \yii\helpers\ReplaceArrayValue([]),
this will prevent langManager
from bootstraping on console.
I have bootstrap component for language switching with cookie, which placed in common/components. In common/config/main.php placed string 'bootstrap' => ['LangManager'], and working nice but when i run console command php yii, it is throw exception Calling unknown method: yii\console\Request::getCookies().
When 'bootstrap' => ['LangManager'] placed in frontend or backend config files, its work good, but i think that it is illogical for user-code core.
| Yii vesion 2.0.8 | | PHP version 7.0.6 | | Operating system Mac OS X/Ubuntu 14.04 |