Create Module Login Admin

I create one module login admin, but instruction return error: Property "AdminModule.user" is not defined.

My code AdminModule it is:





class AdminModule extends CWebModule

{

	public function init()

	{

		// this method is called when the module is being created

		// you may place code here to customize the module or the application


		// import the module-level models and components

		$this->setImport(array(

			'admin.models.*',

			'admin.components.*',

		));


		Yii::app()->setComponents(array(

            'errorHandler' => array(

                'errorAction' => 'admin/default/error',

            ),

            'user' => array(

                'class' => 'CWebUser',

                'stateKeyPrefix' => '_admin',

                'loginUrl' => 'admin/default/login',

            ),

        ));


        Yii::app()->user->setStateKeyPrefix('_admin');

	}


	public function beforeControllerAction($controller, $action) {

        if (parent::beforeControllerAction($controller, $action)) {

            // this method is called before any module controller action is performed

            // you may place customized code here

            $route = $controller->id . '/' . $action->id;

           // echo $route;

            $publicPages = array(

                'default/login',

                'default/error',

            );

            if (Yii::app()->user->isGuest && !in_array($route, $publicPages)){            

                Yii::app()->getModule('admin')->user->loginRequired();                

            }

            else

                return true;

        }

        else

            return false;

    }

}




CWebUser component is only in applicaton not in every module, so:


Yii::app()->getModule('admin')->user->loginRequired();

won’t work by default…

Get idea from these links -

http://www.yiiframework.com/wiki/89/module-based-login

http://www.yiiframework.com/wiki/616/how-to-create-module-based-login

Thanks for help,

i read the wiki, i solved my problem when i remove “getModule(‘customer’)”, i replace the component UserIdentity.php for Indentificador.php and i set my model form to my new UserIdentity. This work for me.

I not understend because don’t work getModule, i followed the post “http://www.yiiframework.com/wiki/89/module-based-login”, and only not insert in my code:


'components' => array(

   ...

   'urlManager' => array(

      'rules' => array(

         'http://customer.example.com' => 'customer/default/index',

         'http://customer.example.com/login' => 'customer/default/login',

      ),

   ),

   ...

),

Your welcome dude :)