Bootstrap Layout Not Working For All Controllers Except Default Controller In Admin Module

I used bootstrap layout for my admin module, It perfectly works for default controller but not for other controllers.

I used this code in AdminModule.php

public function init()


     $this->layoutPath = Yii::getPathOfAlias('admin.views.layouts');

     $this->layout = 'main';


If I use other controllers, It shows default layout, What I use for frontend.

Any help should be appreciable.

Thanks in advance.

The layout path application or main will be set by assigning the property layout.

The default layoutpath of a module controller is the modules layout, so you don’t set the layoutPath and override the init() in your adminmodule.

This should do the same as your init().

AdminController extends CController {

 public $layout='main'; //or '/layouts/main'


  • Adding no ‘layout’ to the viewname:

The default layout path (application layout, or modules layout for module controllers) will be used.

  • Setting ‘/layouts/main’ with one slash is the modules layout path,

  • with two slashes ‘//layouts/main’ the application layout path.

Take a look at column1 / column2 layouts of default Yii applications.

  $this->beginContent('/layouts/main'); //render into module layout


  $this->beginContent('//layouts/main'); //render into application layout

But you problem seems to be another:

Do you include bootstrap in you application main layout?

yeah i included bootstrap in main.php. Actually it works, while am using /admin/default/index after I changed to another controller /admin/activity. It doesn’t show up. I don’t know where I missed.


Finally I found out.

If you want bootstrap layout for all controllers, do this for each controller.


public $layout='admin.views.layouts.main';

If this post is useful to you Click + ;D

The modules layout ‘main’ you have assigned in your init() will be ignored on rendering, if a controller has set his own layout.

 public $layout='xy'; 

So take care about this.

Has the other controllers a layout assigned?

If your controllers extends the ‘Controller’ component (usually placed in protected/components) there is a layout assigned, ‘CController’ has no layout assigned and the configured ‘main’ from your init will be used.

I would debug through the Yii core code with a breakpoint at CController::getLayoutFile().