Yii2 - Getting unknown property: yiiconsoleApplication::user(Yii2 - 获取未知属性:yiiconsoleApplication::user)
问题描述
我正在尝试从终端运行控制台控制器,但我每次都收到此错误
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
这里是控制器
class TestController extends yiiconsoleController {
public function actionIndex() {
echo 'this is console action';
} }
这是concole配置
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
有人可以帮忙吗?
推荐答案
控制台应用程序没有 Yii->$app->user
.所以,你需要在configconsole.php
中配置user
组件.
Console application does not have Yii->$app->user
. So, you need to configure user
component in configconsole.php
.
喜欢,
configconsole.php
'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
或
访问以下链接:Yii2 isGuest 在控制台应用程序中给出异常
注意:控制台应用程序中没有会话.
Note : There's no session in console application.
这篇关于Yii2 - 获取未知属性:yiiconsoleApplication::user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Yii2 - 获取未知属性:yiiconsoleApplication::user


基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 使用 PDO 转义列名 2021-01-01