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
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
