public function actionIndex()
{
$this->render('index');
}
public function actionPage()
{
$this->layout='column1';
$this->render('pages/about');
}
where i am changing my layout depending on actionID.
Now i want to change my layout depending on actionID view ie. on my actionID page i have two views
1.about
2.samples
for both of the views i need different layout. And at same time if my view does not exists it should redirect to error page (or) error layout should be rendered.
as your controller’s property, then in every action change its value according to the layout you want, just like in your given example.
public function actionPage()
{
$this->layout='column1';
$this->render('pages/about');
}
That’s just about it. Just make sure that the layout you are calling exists (under ‘views’ folder), otherwise it won’t work. You might want to read this.
The same stuff goes with the error action (I find it interesting that you want to be prepared for the views that does not exist though)
macinville, controllers already have this property defined CController.layout.
You can do it inside views (actually I always do such assignments in views):
$this->layout = 'layout';
If a view is not found then an exception will be generated. If it’s not a debug mode a user will get error page. But if a layout is not found, a page will be rendered without it.
as Andy said i did the layout property in my view files, but when rendering on actionID view i have a problem.
ie. for my actionID ‘page’ because of i have 2 views
1.about
I should render $this->render(‘pages/about’);
2.samples
I should render $this->render(‘pages/samples’);
how can i compare views and render accordingly in the same actionID (or) having a single render how can i make the second parameter dynamic(next to pages/{$dynamic})