Yii2-获取未知属性:yii\console\Application :: user [英] Yii2 - Getting unknown property: yii\console\Application::user

查看:603
本文介绍了Yii2-获取未知属性:yii\console\Application :: user的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从终端运行控制台控制器,但每次都会收到此错误

I am trying to run a console controller from the terminal, but i am getting this errors every time

Error: Getting unknown property: yii\console\Application::user

这是控制器

class TestController extends \yii\console\Controller {

public function actionIndex() {
    echo 'this is console action';
} }

这是conconle配置

and this is the concole config

return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'modules' => [],
'components' => [
    'log' => [
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                '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->用户。因此,您需要在 config\console.php 中配置 user 组件。

Console application does not have Yii->$app->user. So, you need to configure user component in config\console.php.

就像

config\console.php

 'components' => [
 .........
 ......
        'user' => [
            'class' => 'yii\web\User',
            'identityClass' => 'app\models\User',
            //'enableAutoLogin' => true,
        ],
        'session' => [ // for use session in console application
            'class' => 'yii\web\Session'
        ],
 .......
]

有关您的问题的更多信息,请参见:链接

More info about your problem see this : Link

OR

访问以下链接:
Yii2 isGuest在控制台应用程序中给出异常

注意:在控制台应用程序中没有会话。

Note : There's no session in console application.

这篇关于Yii2-获取未知属性:yii\console\Application :: user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆