yiisoft / yii2-app-advanced

Yii 2.0 Advanced Application Template
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
1.66k stars 1.28k forks source link

Calling unknown method: yii\console\Request::getCookies() with bootstrap #180

Closed xCEZAREx closed 6 years ago

xCEZAREx commented 8 years ago

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 |

samdark commented 8 years ago

It's expected since there are no cookies in console.

tonny-sofijan commented 6 years ago

@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()'

samdark commented 6 years ago

Please show stacktrace for the error.

tonny-sofijan commented 6 years ago

@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!

Faryshta commented 6 years ago

on console/config/main.php include the follwoing line

'bootstrap' => new \yii\helpers\ReplaceArrayValue([]),

this will prevent langManager from bootstraping on console.