Asked  1 Year ago    Answers:  5   Viewed   13 times

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

here is the controller

class TestController extends yiiconsoleController {

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

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

can anyone help please?



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

like as,


 '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


Visit following link : Yii2 isGuest giving exception in console application

Note : There's no session in console application.

Saturday, May 29, 2021

Each attribute may has own settings which might be configured in attribute array. For example, you can configure the data format like:

<?= DetailView::widget([
    'model' => $model,
    'attributes' => [
            'attribute' => 'discription',
            'format' => 'html'
            'label' => ''
]) ?>
Thursday, April 1, 2021

It wasn't necessary to change it:

return [
    'components' => [
        'db' => [
            'class' => 'yiidbConnection',
            'dsn' => 'pgsql:host=localhost;dbname=travel',
            'username' => 'aaaa',
            'password' => 'bbbb',
            'charset' => 'utf8',

Then Gii code generator recognizes the laboratory schema (but autocomplete for Table Name doesn't work).

Thursday, April 1, 2021

You have to add new public property to User.php (model class file) as

class User extends ActiveRecord
    public $repeat_password;

Please refer to this first

It will not take much time.

Don't forget to add its validation rules in rules method of User.php

Thursday, April 1, 2021

The Yii2 guide has excellent documentation in this regard see Upgrade from v1

I recently migrated couple of moderately complex applications from Yii 1.x to Yii 2.0. There are two ways to go about it , either you can run Yii 1.x and Yii 2 at the same time see using-yii-2-with-yii-1. Then migrate part by part, while it is possible it was quite bit of pain, like trying to rebuild the second floor while living on the third.

Alternatively you can rewrite the entire application bottom up with the exact same functionality, I found this to be much more efficient, significant code could be reused with only minor modifications, also that gave opportunity to tweak the design without changing functionality.

The important thing is to ensure the exposed API ( i.e. the frontend / UI / functionality) remains the same. It is always tempting to update functionality or change features during a rewrite, however if you stick to strictly reimplementing everything for Yii2 then consider changing your API, your migration will be smoother.

Tuesday, November 2, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :