1

I want to make a installation script for my app in yii2 and for that I want to redirect it to a defaultRoute='installation/index' but I am getting this namespace error when I have right namespace in my installation controller

Also I have a Installation model which does not extends to the activerecords and is used to get the user input values and perform some actions without the need of saving them into DB but it's directory is also not found.

Below is the error I am getting

Installation controller code:

namespace livecrm\controllers;

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

}

install-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;

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,
];
4
  • 1
    show some code of the controller Commented Sep 17, 2015 at 4:48
  • @ankitraturi added controller code Commented Sep 17, 2015 at 4:53
  • 1
    Hi deepak. it's really hard for us to read your screenshot of code. Could you please instead edit your question and copy/paste your code into your question instead? Commented Sep 17, 2015 at 5:11
  • 1
    That will also help us by letting us copy out the relevant bits with an error and making changes and posting it as an answer for you... Commented Sep 17, 2015 at 5:12

1 Answer 1

2

Seems like you are using basic application template.

The namespace of controller for your case should be:

namespace app\controllers\InstallationController;

The error message is very clear by the way and tells exactly about that.

Update: If you need namespace different than app\controllers you can change it through controllerNamespace property of yii\base\Applcation. For example you can add this to your config:

'controllerNamespace' => 'livecrm\\controllers',

Official docs:

Sign up to request clarification or add additional context in comments.

5 Comments

but all other code of my app is using namespace livecrm/controllers.So I wanted to use the same for this controller also
its based on advanced template and if I change namespace to app/controller then I have to change it all over in the code which is not possible.I will update my ques with config/main.php where I have used default controller namespace as livecrm/controllers
'controllerNamespace' => 'livecrm\controller' is already done in my main.php config file.I have added code of main.php
try 'livecrm\\controllers' instead of 'livecrm\controllers'
@ankitraturi still the same error with 'livecrm\\controllers'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.