two layouts

Hi,

is possible to make 2 different layouts for 2 users? User1 have layout1 and user2 have layout2.

Thanx!

In the constructor of your base controller class, set "layout" property of controller according to the user info.

:) thanx for reply

Hi,

I have still problem. When I set "layout" property in action all work fine but when I try create constructor I have error:

CException

Description

AdminController cannot find the requested view "login".

My class:



class AdminController extends CController


{


	


	function __construct()


	{


		$this->layout = 'admin';


	}


	


	/**


	 * This is the default 'index' action that is invoked


	 * when an action is not explicitly requested by users.


	 */


	public function actionIndex()


	{


		// renders the view file 'protected/views/site/index.php'


		// using the default layout 'protected/views/layouts/main.php'


		$this->render('index');


	}


	


	/**


	 * Declares class-based actions.


	 */


	public function actions()


	{


		return array(


			// captcha action renders the CAPTCHA image


			'captcha'=>array(


				'class'=>'CCaptchaAction',


				'backColor'=>0xEBF4FB,


			),


		);


	}





	/**


	 * Displays a login form to login a user.


	 */


	public function actionLogin()


	{


		$user=new LoginForm;


		// collect user input data


		if(isset($_POST['LoginForm']))


		{


			$user->attributes=$_POST['LoginForm'];


			// validate user input and redirect to previous page if valid


			if($user->validate())


				$this->redirect($this->createUrl('index'));


		}


		// display the login form


		$this->layout = 'login';


		$this->render('login',array('user'=>$user));


	}





	/**


	 * Logout the current user and redirect to homepage.


	 */


	public function actionLogout()


	{


		Yii::app()->user->logout();


		$this->redirect(Yii::app()->homeUrl);


	}


}


Please check the constructor's signature. You should not change it, and you must call the parent constructor. The API doc doesn't say this clearly. I will add an additional init method for this purpose. Thanks.

Thanx for help qiang.

Yet I have:



...


        private $_id;


	


	/**


	 * @param string id of this controller


	 */


	public function __construct($id)


	{


		$this->_id=$id;


		parent::__construct($id);


		


		$this->layout = 'admin';


	}





...


Earlier I tried call parent constructor but too didn`t work. Maybe private variable helped?

Now work, thanx.

It's because you should call the parent constructor with the needed $id parameter, which tells the controller which action is being requested.