How to create logins for different modules

In my Yii 1.x application I defined new Admin module. In the init method of the admin module I defined new user component like this:




 $this->setComponents(array(

    			'user'=>array(

    				'class' => 'CWebUser',

    				// enable cookie-based authentication

    				'allowAutoLogin'=>true,

    				'baseUrl'=>Yii::app()->createUrl("admin/user/login"),

    				'stateKeyPrefix' => '_admin',

    			),

    		));

Now, I expect I can do the following:


Yii::app()->getModule("admin")->user->login($this->_identity,$duration)

or


  Yii::app()->getModule("admin")->user->logout();

but it is not working.

When I print my module (var_dump(Yii::app()>getModule("admin"))) I can see that user component is not defined.





    object(AdminModule)[14]

      public 'defaultController' => string 'default' (length=7)

      public 'layout' => null

      public 'controllerNamespace' => null

      public 'controllerMap' => 

        array (size=0)

          empty

      private '_controllerPath' (CWebModule) => null

      private '_viewPath' (CWebModule) => null

      private '_layoutPath' (CWebModule) => null

      public 'preload' => 

        array (size=0)

          empty

      public 'behaviors' => 

        array (size=0)

          empty

      private '_id' (CModule) => string 'admin' (length=10)

      private '_parentModule' (CModule) => null

      private '_basePath' (CModule) => string '/srv/www/htdocs/public/project/application/protected/modules/admin' (length=71)

      private '_modulePath' (CModule) => null

      private '_params' (CModule) => null

      private '_modules' (CModule) => 

        array (size=0)

          empty

      private '_moduleConfig' (CModule) => 

        array (size=0)

          empty

      private '_components' (CModule) => 

        array (size=0)

          empty

      private '_componentConfig' (CModule) => 

        array (size=1)

          'user' => 

            array (size=4)

              'class' => string 'CWebUser' (length=<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />

              'allowAutoLogin' => boolean true

              'baseUrl' => string '/project/application/index.php/admin/user/login' (length=52)

              'stateKeyPrefix' => string '_admin' (length=11)

      private '_e' (CComponent) => null

      private '_m' (CComponent) => null

If you encounter this problem, then the second parameter of the setComponent method should be set to false.


$this->setComponents(array( 'user'=>array( 'class' => 'CWebUser', // enable cookie-based authentication 'allowAutoLogin'=>true, 'baseUrl'=>Yii::app()->createUrl("admin/user/login"), 'stateKeyPrefix' => '_admin', ), ), false);