Can the layout be set inside a view file? I see it can be done within the controller, but didn't find anything about setting it within a view file. In the documentation, it's stated that it can also be changed using CWebApplication:Layout. I didn't see an method there to set the layout file.
I already tried that and it doesn’t change the layout. The new layout file is in the same directory as the main.php layout file so I can’t see it being a path issue. I checked the path by echoing Yii::app()->layoutPath and it is protected/views/layouts. I tried to assign it as follows in the view.
<?php $this->layout=“newlayout”; ?>
. Newlayout being newlayout.php.
It works fine when I change it within the contoller class using $layout = "newlayout".
I also echoed $this->layout after assigning the new layout and it does return the new layout file name, but the layout is not changing when refreshing. The newlayout file definitely has a different layout which has been tested by changing it within the controller class.
Ah, thank you for finding out this. I just fixed it. It is because layout was determined before the view is actually rendered. I just swapped the order. It should work now.
you will need to use SVN or download from nightly snapshot (the fix will be in tomorrow's snapshot). Check the download page. The fix is currently in 1.0 branch.
Your action classes don't need to create the controller instance because it is already there. You can set the "layout" property in your TestController class:
<?php
class TestController extends CController
{
public $layout="xyz";
}