Yii 1.1: How to Setting Layouts in Yii

6 followers

usually someone confused to make layouts in yii.

and how do to make layouts in yii? whether to change the CSS Default? or should create a new css file? Okay I will explain a bit about how to create layouts in yii.

let us consider

The first thing you should do is download the file layouts that are small in Yii Layouts

there are several options, you can choose one layouts. example: I use the Triplets and now go to the folder Triplets / layouts / and copy files triplets.php

and paste into YourApplication / protected / views / layouts

after finished moving files to a folder triplets.php layouts, now you have to set the configuration. Now enter the folder

YourApplication / protected / components / and open the file Controller.php

after the change as below.

<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
    /**
     * @var string the default layout for the controller view. Defaults to '//layouts/column1',
     * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
     */
    public $layout='//layouts/triplets';/ / change the layouts here with triplets or others
 
    /**
     * @var array context menu items. This property will be assigned to {@link CMenu::items}.
     */
    public $menu=array();
    /**
     * @var array the breadcrumbs of the current page. The value of this property will
     * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
     * for more details on how to specify this property.
     */
    public $breadcrumbs=array();
}

--additional--

If you want the sidebar on any existing controller. you have to add the same code.

I will be demonstrated. Here I have the News Controller and I've added a sidebar to The News, see the following code:

class NewsController extends Controller
{
        .....
    /**
     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
     * using two-column layout. See 'protected/views/layouts/column2.php'.
     */
    public $layout='//layouts/righty'; // change your code here
        .....
}

in fact it's the same code with the previous code. its just different controller

--additional--

completed

make it easy yeah I hope this helps

working safely.

Total 2 comments

#13356 report it
ruderbytes at 2013/05/24 05:13am
Thanks
What you described is useful if you need to override the main layout for the entire app. It can be overriden for each contrller, even action. Actually is pretty simple to make a system to apply layouts for each request - you only need to store somewhere the layout to use for each entity (say a page in a cms) and apply it in the view action in the controller. It can even be set in the view (a render not partialRender one) :), because it is a public variable and the flow of the application allows it.

Urecheatu007 Thanks For Your Suggestion : )

#13180 report it
urecheatu007 at 2013/05/11 02:57pm
Some aditional info

What you described is useful if you need to override the main layout for the entire app. It can be overriden for each contrller, even action. Actually is pretty simple to make a system to apply layouts for each request - you only need to store somewhere the layout to use for each entity (say a page in a cms) and apply it in the view action in the controller. It can even be set in the view (a render not partialRender one) :), because it is a public variable and the flow of the application allows it.

Leave a comment

Please to leave your comment.

Write new article