获取未知属性:yii\console\Application :: session while ./yii

Dar*_*ber 1 php yii2

我想运行yii2 console命令,然后我运行它测试它 ./yii

当我跑步时,./yii我得到了这个回应

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')
Run Code Online (Sandbox Code Playgroud)

这是我的 common/config/params-local.php

return [
        'uploadPath' => __DIR__ .'/../../uploads/',
        'baseurl' => 'http://localhost/myweb/'
];
Run Code Online (Sandbox Code Playgroud)

这是我的 common\config\params.php

<?php
return [
    'adminEmail' => 'no-reply@myweb.com',
    'supportEmail' => 'no-reply@myweb.com',
    'user.passwordResetTokenExpire' => 3600,
];
Run Code Online (Sandbox Code Playgroud)

这是我的 console\config\params-local.php

<?php
return [
];
Run Code Online (Sandbox Code Playgroud)

这是我的 console\config\params.php

<?php
return [
    'adminEmail' => 'no-reply@myweb.com',
];
Run Code Online (Sandbox Code Playgroud)

这是我的 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',
            ]

    ],
];
Run Code Online (Sandbox Code Playgroud)

这是我的 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',
                ],
            ],


        ],
    ],
    ]
];
Run Code Online (Sandbox Code Playgroud)

看起来我的脚本出了问题.目前我正在使用ubuntu.

如果要解决这个问题,我该怎么办?所以它应该用yii命令列表而不是错误响应.

什么原因导致这些错误?

提前致谢.

mey*_*sam 5

当您添加值common/config夹中的文件,像所有的应用程序使用的配置backend,frontend,console,api等.因此,在高级模板中,您只需添加与所有这些应用程序相关的值.基于文档 common文件夹是所有应用程序通用的文件.这张照片清楚地显示:

在此输入图像描述

对于你的问题,正如其他人提到的,你没有任何session在控制台,但你添加或使用此模块,common/config/params-local.php并基于这个答案的介绍,它将被使用console/config/params-local.php,你得到一个错误:).

更新:根据您更新的问题,您的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',
            ]

    ],
];
Run Code Online (Sandbox Code Playgroud)

gridviw模块,隐式session用于保存排序状态.在另一方面,您将此添加到config文件夹中common,因此基于之前的注释,它也将在console应用程序中使用.控制台没有session(我认为您的控制台中不需要网格视图:D)并且它会导致错误.要解决此问题,请移动此行

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

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

        ],
Run Code Online (Sandbox Code Playgroud)

main.phpfrontendbackend文件夹(根据您的情况和使用).