[Solved] Alias “nordsoftware.yii_account” is invalid. Make sure it points to an existing directory or file.

When I integrate yii_account (https://github.com/nordsoftware/yii-account) to my application with Yii version 1.1.6, I encounter the folling error.

Alias “nordsoftware.yii_account” is invalid. Make sure it points to an existing directory or file.

I search the error in the google engine. Only two pages of result are matched.

==================== You can find the solution here, please read it carefully ==================

Sometimes it’s useful to namespace the whole module. For example, if you want to put testmodule under\mynamespace\modules\testmodule pointing to /var/www/common/mynamespace/modules/testmodule you should first create the following file structure:

/var/www/common/mynamespace/modules
  testmodule
    controllers
      DefaultController.php
    views
      default
        index.php
    TestmoduleModule.php

index.php view is the same as in regular module. TestmoduleModule.php and DefaultController.php are namespaced.

TestmoduleModule.php:

// define namespace:
namespace mynamespace\modules\testmodule;

// since class is now under namespace, global namespace
// should be referenced explicitly using "\":
class TestmoduleModule extends \CWebModule
{
    // setting non-global controllers namespace (also can be done via config)
    public $controllerNamespace = '\mynamespace\modules\testmodule\controllers';

    // usual module code
}

DefaultController.php:

<?php
// define namespace:
namespace mynamespace\modules\testmodule\controllers;

// since class is now under namespace, global namespace
// should be referenced explicitly using "\":
class DefaultController extends \Controller
{
    public function actionIndex()
    {
        $this->render('index');
    }
}

Now the only thing left is to add our module to the application. The best way to do it is to specify it in the application config file (protected/config/main.php):

// adding "mynamespace" namespace
Yii::setPathOfAlias('mynamespace', '/var/www/common/mynamespace/');

return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'My Web Application',

    'modules'=>array(
        'testmodule' => array(
            'class' => '\mynamespace\modules\testmodule\TestModuleModule',
        ),
    ),

Full Configuration

config/main.php

'aliases' => array(
    ......
    'nordsoftware' => __DIR__ . '/../modules/nordsoftware',
    ......
),

'modules' => array(
    ......
    'account' => array(
            'class' => '\nordsoftware\yii_account\Module',
        ),
    ......
),

'components' => array(
    ......
    'user' => array(
            'class' => '\nordsoftware\yii_account\components\WebUser',
    )
    ......
),
class Module extends \CWebModule
{
    public $controllerNamespace = '\nordsoftware\yii_account\controllers';
    ......

After reading this article, you can find the key point with red color labeled. If you want to search more about it, you can search with keyword “namespaced module in yii”

For details of namespace and alias, please check http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace