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

时间:2017-02-06 04:39:39

标签: 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')

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

return [
        'uploadPath' => __DIR__ .'/../../uploads/',
        'baseurl' => 'http://localhost/myweb/'
];

这是我的common\config\params.php

<?php
return [
    'adminEmail' => 'no-reply@myweb.com',
    'supportEmail' => 'no-reply@myweb.com',
    'user.passwordResetTokenExpire' => 3600,
];

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

<?php
return [
];

这是我的console\config\params.php

<?php
return [
    'adminEmail' => 'no-reply@myweb.com',
];

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

    ],
];

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


        ],
    ],
    ]
];

我的脚本看起来有问题。 目前我正在使用ubuntu。

如果要解决此问题,我该怎么办?所以它应该使用yii命令列表而不是错误进行响应。

导致这些错误的原因是什么?

提前致谢。

1 个答案:

答案 0 :(得分:5)

common/config文件夹文件添加值时,所有应用程序中使用的配置如backendfrontendconsoleapi等。因此,在高级模板中,您只需添加与所有这些应用程序相关的值。基于documentation common文件夹的是所有应用程序通用的文件。这张照片清楚地显示出来:

enter image description here

对于您的问题,正如其他人提到的,您在控制台中没有任何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',
            ]

    ],
];

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

session

'modules' => [ 'redactor' => [ 'class' => 'yii\redactor\RedactorModule', 'uploadDir' => __DIR__ .'/../../uploads/konten', 'uploadUrl' => '/myweb/uploads/konten', 'imageAllowExtensions'=>['jpg','png','gif'] ], 'gridview' => [ 'class' => '\kartik\grid\Module', ] ], main.php文件夹的frontend(根据您的情况和用途)。