Set Layout For Submodules

I have created the module ‘admin’. This module has 2 files inside the layouts folder: login.php and admin.php. Now I have a working login page with the right layout(login.php).

Inside the admin module I have created a submodule called ‘dashboard’.

After the login I redirect the user to the dashboard submodule:




public function actionIndex()

	{

	// check if the user is logged in

	if(Yii::app()->user->isGuest)

	{

		$this->redirect(array('login'));

	}

	else

	{

		$this->redirect(array('dashboard'));

	}

}



Now I want to have all submodules inside the ‘admin’ module to have the admin.php layout. How do I get this working?

You can set the layoutPath to the parent modules layoutPath on init()

Set the modules layout to admin or set all controllers $layout=‘admin’





public function init()

{

  $this->setLayoutPath($this->getParentModule()->getLayoutPath());

  $this->layout='admin';

...

}