Yii Framework Forum: two layouts - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

two layouts Rate Topic: -----

#1 User is offline   qwerty 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 290
  • Joined: 20-November 08

Posted 13 December 2008 - 03:40 AM

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

Thanx!
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 December 2008 - 07:38 AM

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

#3 User is offline   qwerty 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 290
  • Joined: 20-November 08

Posted 13 December 2008 - 07:55 AM

:) thanx for reply
0

#4 User is offline   qwerty 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 290
  • Joined: 20-November 08

Posted 14 December 2008 - 06:47 AM

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);
}
}

0

#5 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 14 December 2008 - 08:12 AM

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.
0

#6 User is offline   qwerty 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 290
  • Joined: 20-November 08

Posted 14 December 2008 - 09:40 AM

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.
0

#7 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 14 December 2008 - 01:20 PM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users