1

I want to run yii2 console command, then I test it with run this ./yii

When I run ./yii I got this response

Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: yii\console\Application::session'

in /var/www/html/myweb/vendor/yiisoft/yii2/base/Component.php:143

Stack trace:
#0 /var/www/html/myweb/vendor/yiisoft/yii2/di/ServiceLocator.php(73): yii\base\Component->__get('session')
#1 /var/www/html/myweb/vendor/kartik-v/yii2-grid/Module.php(62): yii\di\ServiceLocator->__get('session')

Here is my common/config/params-local.php

return [
        'uploadPath' => __DIR__ .'/../../uploads/',
        'baseurl' => 'http://localhost/myweb/'
];

Here is my common\config\params.php

<?php
return [
    'adminEmail' => '[email protected]',
    'supportEmail' => '[email protected]',
    'user.passwordResetTokenExpire' => 3600,
];

Here is my console\config\params-local.php

<?php
return [
];

Here is my console\config\params.php

<?php
return [
    'adminEmail' => '[email protected]',
];

Here is my common\config\main.php

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],      
    ],
    'modules' => [
            'redactor' => [
                    'class' => 'yii\redactor\RedactorModule',
                    'uploadDir' => __DIR__ .'/../../uploads/konten',
                    'uploadUrl' => '/myweb/uploads/konten',
                    'imageAllowExtensions'=>['jpg','png','gif']
            ],

            'gridview' =>  [
                    'class' => '\kartik\grid\Module',
            ]

    ],
];

Here is my common\config\main-local.php

<?php
return [
    'language' => 'en-US',
    'sourceLanguage' => 'id-ID',
    'components' => [
            'authClientCollection' => [
                    'class' => 'yii\authclient\Collection',
                    'clients' => [
                            'google' => [
                                    'class' => 'yii\authclient\clients\Google',
                                    'clientId'     => 'xxxxx-cppd86jm9qfrt77pc684pau01nilf261.apps.googleusercontent.com',
                            ],
                            'facebook' => [
                                    'class' => 'yii\authclient\clients\Facebook',
                                    'authUrl' => 'https://www.facebook.com/dialog/oauth?display=popup',
                                    'clientId'=> 'xxxxxx16917400',
                                    'clientSecret' => 'xxxxxx8d99ff80ce1f713424',
                            ],
                    ],
            ],

        'db' => [
                'class' => 'yii\db\Connection',
                'dsn' => 'pgsql:host=192.168.0.106;dbname=mydb',
                'username' => 'dev',
                'password' => 'dev123',
                'charset' => 'utf8',
                'enableSchemaCache' => false,
                'schemaMap' => [
                  'pgsql'=> [
                    'class'=>'yii\db\pgsql\Schema',
                    'defaultSchema' => 'public2' //specify your schema here
                  ]
                ], // PostgreSQL
        ],

        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],

        'mail' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@backend/mail',
            'useFileTransport' => false,//set this property to false to send mails to real email addresses
            //comment the following array to send mail using php's mail function

            'transport' => [
                    'class' => 'Swift_SmtpTransport',
                    'host' => 'iix70.hosting.com',
                    'username' => 'myuser',
                    'password' => 'mypass',
                    'port' => '465',
                    'encryption' => 'ssl',
            ],
        ],
        'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '../../messages',
                'sourceLanguage' => 'id-ID',
                'fileMap' => [
                    'app' => 'app.php',
                ],
            ],


        ],
    ],
    ]
];

Looks like something wrong with my script. Currently i'm using ubuntu.

What should I do next in case to fix that? so it should response with yii command list instead of error.

and what cause these error?

Thanks in advance.

3
  • Please include params-local.php.
    – topher
    Feb 6, 2017 at 6:19
  • The console application does not have a session I believe. A session involves a cookie and I do not believe the console application can handle that.
    – Mihai P.
    Feb 6, 2017 at 6:23
  • @topher in which file I should include params-local.php? @MihaiP. then how to fix these error? Thanks in advance.
    – Dark Cyber
    Feb 6, 2017 at 8:05

1 Answer 1

5

When you add a value to common/config folder files, configurations used in all applications like backend, frontend, console, api and others. So in advanced template, you must just add values which are related to all these applications. Based on documentation common folder is files common to all applications. This picture shows it clearly:

enter image description here

For your problem, as others mentioned, you don't have any session in console, but you added or used this module in common/config/params-local.php and based on introduction of this answer, it will be used in console/config/params-local.php and you get an error :).

Update: Based on your updated question, your common/config/main.php file is:

<?php
return [
    'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],      
    ],
    'modules' => [
            'redactor' => [
                    'class' => 'yii\redactor\RedactorModule',
                    'uploadDir' => __DIR__ .'/../../uploads/konten',
                    'uploadUrl' => '/myweb/uploads/konten',
                    'imageAllowExtensions'=>['jpg','png','gif']
            ],

            'gridview' =>  [
                    'class' => '\kartik\grid\Module',
            ]

    ],
];

gridviw module, implicitly uses session for saving state of sorting. In other side you added this to config folder of common, so based on previous notes, it also will be used in console application. Console doesn't have session (and I think you don't need a grid view in your console :D) and it causes an error. For solving this problem, move this lines

   'modules' => [
                'redactor' => [
                        'class' => 'yii\redactor\RedactorModule',
                        'uploadDir' => __DIR__ .'/../../uploads/konten',
                        'uploadUrl' => '/myweb/uploads/konten',
                        'imageAllowExtensions'=>['jpg','png','gif']
                ],

                'gridview' =>  [
                        'class' => '\kartik\grid\Module',
                ]

        ],

to main.php of frontend or backend folder (based on your situations and use).

4
  • sorry I still didn't understand how to fix that, so I update my question with code in params-local.php and params.php
    – Dark Cyber
    Feb 21, 2017 at 3:48
  • @DarkCyber So I think the problem is in your common/config/main.php or common/config/main-local.php. Can you attach them to your question? May you add yii2-grid module to modules section one of this files.
    – meysam
    Feb 23, 2017 at 5:02
  • 1
    @DarkCyber Please see the updated answer. Don't hesitate to inform me if you have any problem about it.
    – meysam
    Feb 23, 2017 at 9:58
  • @meysam updated the answer and it helped me too, as i was also getting the same problem , you need to move the module configuration of the kartik/gridview to the frontend and backend specific config/main.php files May 28, 2017 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.