Yii2 - yii\console\Application::getSession()

yii2 console
yii2 options
yii2 cron job
yii2 console log
yii2 commands folder
yii2 document
yii2 execute shell command
yii2 tutorial

I am trying to run a console application from the terminal, but am getting this error

Calling unknown method: yii\console\Application::getSession()

this is the controller

class BeanstalkController extends \yii\console\Controller {

public function actionIndex() {

    echo 'this is console action';
} }

and this is the console config

return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'modules' => [],
'components' => [
    'user' => [
        'class' => 'yii\web\User',
        'identityClass' => 'common\models\Users',
        'enableAutoLogin' => TRUE,
    ],
    'log' => [
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
        ],
    ],
],
'params' => $params,];

I tried to remove the session from the config but am still getting the session error.

Anyone can help ?

Correct config in console env is:

'components' => [
            'user' => [
                'class' => 'yii\web\User',
                'identityClass' => 'app\models\User',
                'enableSession' => false,
                'enableAutoLogin' => false,
            ],
        ],

Calling unknown method: yii\console\Application::getSession , To run the console application, enter the following on the command line: yii It then calls yii\console\Controller::runAction() to run the action with the given  Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

You cannot use Application::getSession() because yii\console\Aplicationis different than web aplication.

http://www.yiiframework.com/doc-2.0/yii-console-application.html

Try to add session component to your config.

return [
    'id' => 'app-console',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'console\controllers',
    'modules' => [],
    'components' => [
        'user' => [
            'class' => 'yii\web\User',
            'identityClass' => 'common\models\Users',
            'enableAutoLogin' => TRUE,
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'session' => [ 
            'class' => 'yii\web\Session'
        ],
    ],
    'params' => $params,
];

And use it as a component

Yii::$app->session->get('session');

Application, yii\console\Application, 'name' => 'Project Browser Console Application', // application public function init() { parent::init(); Yii::app()->getSession()->open();  Application represents a console application. Application extends from yii\base\Application by providing functionalities that are specific to console requests. In particular, it deals with console requests through a command-based approach: A console application consists of one or several possible user commands;

So the reason why every option i tried is not working is that my Yii2 version is old, i had to upgrade to the latest version to get everything working perfectly.

Thank you for the help.

Accessing Model in Console Application - General Discussion, You cannot use Application::getSession() because yii\console\Aplicationis different than web aplication. http://www.yiiframework.com/doc-2.0/yii-console-  The structure of console applications is very similar to a Yii web application. It consists of one or more yii\console\Controller classes, which are often referred to as commands in the console environment. Each controller can also have one or more actions, just like web controllers. Both project templates already have a console application

In console/config/main.php:

return [
   'components' => [
       'user' => null,
       // and put there other components which use a PHP-session
    ]
]

Yii2 - Getting unknown property: yii\console\Application::user, Я пытаюсь запустить консольное приложение с терминала, но я получаю эту ошибку. Calling unknown method: yii\console\Application::getSession(). Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Yii2 - yii \ console \ Application :: getSession () – 4 Ответа, Вызов неизвестного метода: yii \ console \ Application :: getSession () '. Сессия (session) – это некоторый отрезок во времени, в пределах  Application is the base class for all web application classes. For more details and usage information on Application, see the guide article on applications.

Yii2 - yii \ console \ Application :: getSession(), Вы не можете использовать Application::getSession() , потому что yii\console\​Aplication отличается от использования в Интернете. If you want to use database as storage medium, yii\web\DbSession is a better choice. The following example shows how you can configure the application to use CacheSession: Add the following to your application config under components: 'session' => [ 'class' => 'yii\web\CacheSession', // 'cache' => 'mycache',]

Exception 'yii\base\UnknownMethodException' with message , #1 /Users/steven/Code/vetscripts/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('expiring', By default, then, the console was going to the web controller, I'm assuming. use craft\console\Application as Console public function init() { if (Craft::$app instanceof Console)  Error: Getting unknown property: yii\console\Application:: user. aquí es el controlador de . class TestController extends \yii\console\Controller {public function actionIndex {echo 'this is console action';}} y este es el concole config

Comments