Reputation: 18316
I am implementing a template for a Yii project. The website has different frontpage and inner page template.
I know I have to change layout files, But how can I have those different templates for pages ?
Upvotes: 1
Views: 888
Reputation: 9357
You can do that in the controller. For example my website looks the same except for a few pages. One of them is the login page. In the SiteController I have declared the actionLogin like this:
/**
* Displays the login page
*/
public function actionLogin()
{
$this->layout = '//layouts/simple';
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
//$this->redirect(Yii::app()->user->returnUrl);
$this->redirect(array('/'));
}
// display the login form
$this->render('login',array('model'=>$model));
}
The line $this->layout = '//layouts/simple'; overwrites the default layout (main) with the simple layout. If different controllers use different layouts you can also make this a controller wide change by declaring the variable in the controller
public $layout='//layouts/column2';
Upvotes: 7