Yii2 - Getting unknown property: yiiconsoleApplication::user(Yii2 - 获取未知属性:yiiconsoleApplication::user)
问题描述
我正在尝试从终端运行控制台控制器,但我每次都收到此错误
I am trying to run a console controller from the terminal, but i am getting this errors every time
Error: Getting unknown property: yiiconsoleApplication::user
这里是控制器
class TestController extends yiiconsoleController {
public function actionIndex() {
echo 'this is console action';
} }
这是concole配置
and this is the concole config
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'consolecontrollers',
'modules' => [],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yiilogFileTarget',
'levels' => ['error', 'warning'],
],
],
],
],
'params' => $params];
我尝试使用这些命令运行它但没有运气
I tried running it using these commands with no luck
php yii test/index
php yii test
php ./yii test
有人可以帮忙吗?
推荐答案
控制台应用程序没有 Yii->$app->user
.所以,你需要在configconsole.php
中配置user
组件.
Console application does not have Yii->$app->user
. So, you need to configure user
component in configconsole.php
.
喜欢,
configconsole.php
'components' => [
.........
......
'user' => [
'class' => 'yiiwebUser',
'identityClass' => 'appmodelsUser',
//'enableAutoLogin' => true,
],
'session' => [ // for use session in console application
'class' => 'yiiwebSession'
],
.......
]
有关您的问题的更多信息,请参阅:链接
More info about your problem see this : Link
或
访问以下链接:Yii2 isGuest 在控制台应用程序中给出异常
注意:控制台应用程序中没有会话.
Note : There's no session in console application.
这篇关于Yii2 - 获取未知属性:yiiconsoleApplication::user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Yii2 - 获取未知属性:yiiconsoleApplication::user


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01