How to use application layout files in modules?

Hi, guys.

I have two app controllers here.

"AppController_A" (which has "app_layout_a")

"AppController_B" (which has "app_layout_b")

The application default layout is "app_layout_a" in my config file.

And in my module, there are also two controllers like,

"ModController_A" and "ModController_B".

Both of them have no layout file.

When "AppController_A" links to "ModController_A",

ModController_A uses "app_layout_a".

This is fine.

But, "AppController_B" links to "ModController_B",

"ModController_B" uses "app_layout_a" too.

I want to use "app_layout_b" in "ModController_B".

So I write some code in ModController_B::init() like following:



	public function init(){


		Yii::log(Yii::app()->layoutPath, 'info', '');


		$this->layout = 'app_layout_b';


	}


This doesn't work.

Though, log shows layoutPath is application layout path.

It makes no sense to me.

Does anyone help?

Regards.

The current behavior is like: if you set the layout for a module controller and the layout for the module is not set, then the layout will only be searched under the module's layout path.

I agree with you this is not reasonable. As a workaround, you may set the controller layout using dot syntax "application.layouts.app_layout_b". I will make the whole view/layout resolution more reasonable in version 1.1.

Thanks Qiang.

I didn't happen to think about path alias.

I use it.

And I'm looking forward to Yii-1.1.0.

Hey, I tried it.

It works like:



$this->layout = 'application.views.layouts.app_layout_b';


I need to insert 'views' into path alias.

Thanks qiang.