yii2控制器中的命名空间错误

时间:2015-09-17 04:41:12

标签: php yii2

我想在yii2中为我的应用程序制作一个安装脚本,为此我想将其重定向到defaultRoute='installation/index',但是当我的安装控制器中有正确的命名空间时,我收到此命名空间错误

我还有一个安装模型,它没有扩展到activerecords,用于获取用户输入值并执行一些操作,而不需要将它们保存到DB中,但也找不到它的目录。

Below is the error I am getting

安装控制器代码:

namespace livecrm\controllers;

class InstallationController extends \yii\web\Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }

}

安装-config.php中:

$config = [
    'id' => 'app-livecrm',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],

    'defaultRoute' => '/installation/index',
    'components' => [
        'request' => [
            'cookieValidationKey' => 'JDqkJaMgIITAKcsJY6yvLQdM9jf7WghX',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'livefactory\models\User',
            'enableAutoLogin' => false,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
    ],
];
return $config;

配置/ main.php:

$params = array_merge(
    require(__DIR__ . '/../../livefactory/config/params.php'),
    require(__DIR__ . '/../../livefactory/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [



    'id' => 'app-livecrm',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'livecrm\controllers',
    'bootstrap' => ['log'],
    'modules' => [

        'gii' => [
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '*'] // adjust this to your needs
],

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

         'liveobjects' => [
            'class' => 'livefactory\modules\liveobjects\Module',
        ],
         'pmt' => [
            'class' => 'livefactory\modules\pmt\Module',
        ],
         'user' => [
            'class' => 'livefactory\modules\user\Module',
        ],
         'sales' => [
            'class' => 'livefactory\modules\sales\Module',
        ],
         'customer' => [
            'class' => 'livefactory\modules\customer\Module',
        ],
        'product' => [
            'class' => 'livefactory\modules\product\product',
        ],
        'cron' => [
            'class' => 'livefactory\modules\cron\Module',
        ],


    ],
    'components' => [
        'user' => [
            'identityClass' => 'livefactory\models\User',
            'enableAutoLogin' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'authManager'=>[
            'class' => 'yii\rbac\DbManager',
            'defaultRoles' =>['guest'],
        ],
        'as access' => [
            'class' => 'mdm\admin\components\AccessControl',
            'allowActions' => [
                'site/*', // add or remove allowed actions to this list
            ]
        ],
    ],

    'params' => $params,
];

1 个答案:

答案 0 :(得分:1)

好像你正在使用基本的应用程序模板。

您案例的控制器名称空间应为:

namespace app\controllers\InstallationController;

顺便说一下,错误信息非常清楚,并准确地说明了这一点。

更新:如果您需要的命名空间不同于app\controllers,则可以通过controllerNamespace的{​​{1}}属性进行更改。例如,您可以将其添加到您的配置中:

yii\base\Applcation

官方文档: