Yii2 - Getting unknown property: yii\console\Application::user

Tareq Albajjaly

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

here is the controller

class TestController extends \yii\console\Controller {

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

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

can anyone help please?

GAMITG

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

like as,

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

Visit following link : Yii2 isGuest giving exception in console application

Note : There's no session in console application.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting unknown property Exception in yii2

Getting unknown property: yii\web\User::admin

Yii2 - Getting unknown property: yii\console\Request::userAgent and Class db does not exist

Yii2 Login from DB (Setting unknown property: app\models\User::password_hash)

Unknown Property and programatically adding textfields in Yii2 form

Getting unknown property: yii\db\ActiveQuery::reg_no

Error: getting unknown property: yii\web\Application::generateid

Twitter API : Not Getting User Email - Yii2

Eerror in social login in Yii2: Setting unknown property: yii\web\Application::authClientCollection

Yii2 Setting unknown property: yii\filters\auth\HttpBearerAuth::formats

Yii2 migrate Setting unknown property: yii\caching\FileCache::backuprestore

Getting property from unknown interface

Using property of parent class gives "unknown property" error in php (yii2)

Getting unknown property 'classpath' with Jack compiler for Android

Yii Framework Unknown Property Exception

yii2 beginWidget -> unknown method

Unknown Method - ActiveField::radioButtonList() in Yii2

Setting unknown property: yii\web\UrlRule::GET

Setting unknown property: yii\grid\GridView::export

Unknown Property – yii\base\UnknownPropertyException ::discription:html

Setting unknown property: yii\validators\NumberValidator::0

What is a reason of getting error: "Unknown property '' on class MyBean"?

getting value from collection using unknown property name

Angular bind to svg text element getting unknown property error

Unknown Class – yii\base\UnknownClassException Yii2

Calling unknown method: yii\web\Application::createUrl() in yii2

Yii2 - getting sum of a column

Getting extra data in ajax in Yii2

Yii2 getting sum of a column