Reputation: 899
Well, this part is very important. I'm working on a project with YII. I faced a problem like, I was trying to set one of my action in controller with a layout. 1st of all, this action not even taking the default layout mentioned, where another action actionIndex()
is working fine on the same controller. Then I tried for $this->layout='//layouts/new'
in the controller even triend it on the view rendering to the controller. That's even not working. I checked whether it returns any $content
to the layout new.php
or not. But it's not even coming to new.php. die()
is not working even if I put it on the 1st line of the layout. I need help on this.
Upvotes: 1
Views: 7213
Reputation: 791
put this in your controller (yii 1.1)
public function beforeAction($action) {
$this->layout = '//layouts/newlayout';
return true;
}
Upvotes: 0
Reputation: 412
It sounds to me like your action is not even making it to where it needs to render the view. There is likely some sort of error in the action code prevent it from progressing to the end. For testing, clear out all code in the action other than the following, and post your error here.
$this->layout = '//layouts/new';
$this->render('view',array(
'model'=>$model,
));
This assumes that you have defined the following layout and view:
protected/views/layouts/new.php
protected/views/<controllername>/view.php
new.php is where you will echo $content, and view.php is where you will display the $model information
Upvotes: 3
Reputation: 1633
public function actionTest() {
$this->layout = 'new';
$this->render('test');
}
create new layout in views/layouts folder.
Upvotes: 4