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 configureuser
component inconfigconsole.php
.like as,
configconsole.php
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.