Yii Framework Forum: Parent Module layout path - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Parent Module layout path Rate Topic: -----

#1 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 19 January 2010 - 06:02 AM

Hi,

I have the following structure:

-protected
--modules
---admin
----modules
-----core
------controllers
-------IndexController.php
------views
----views
-----layouts
------main.php
-----CoreModule.php

As you can see i am using modules and child modules. Now this works fine. I would like to point your attention to one of the features available within Yii framework, The layouts.

At this time all i did was to add main.php to the admin/views/layouts/ directory and i hoped that all my child modules controllers will use that layout file.

Now when i create and add the main.php layout file to the admin/modules/core/views/layouts directory it feeds from that directory as it should, How ever when i remove that file it won't print any layout even though the layout exists in the parent module which is the admin module.

Now When i ever i add the same layout file into the directory Protected/views/layouts with the name main.php as the default name used by the framework it does work and uses that layout from that path (Protected/views/layouts/main.php).

Now according to the Documentation and i quote

CWebModule:

"the layout that is shared by the controllers inside this module. If a controller has explicitly declared its own layout, this property will be ignored. If this is null (default), the application's layout or the parent module's layout (if available) will be used. If this is false, then no layout will be used."

Notice the highlighted text that explains that if the property left as it is by default which is Null then it will try to locate it through the currently used module layout directory (admin/modules/core/views/layouts/main.php) Other wise it will try to look for the layout under the applications layouts (Protected/views/layouts/main.php) If both fails (I assume) then it will try to look for under it's parent module layout path (modules/admin/views/layouts/main.php). The first two options works

admin/modules/core/views/layouts/main.php
Protected/views/layouts/main.php

If i remove both of them the third one which should work as well if the first two fails, Fails as well.

I was wondering if anyone encountered this issue or maybe this is a bug and needs reporting.

Any help will be appreciated.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 21 January 2010 - 02:36 AM

Bump.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#3 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 376
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 22 January 2010 - 07:08 AM

Maybe you have defined 'layout' variable inside CoreModule.php?
Yes, It Is!
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 03 February 2010 - 05:08 PM

see this post it looks related:

http://www.yiiframew...ath-for-module/
0

#5 User is offline   csdaraujo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 06-August 10
  • Location:Brasil

Posted 26 August 2010 - 08:20 AM

I don't know if this will help anyone, but I did an ugly hack to set my layout inside a controller inside a submodule.

I set the $layout like this on the controller:
public $layout='//../modules/mymodule/views/layouts/column2';



This made my controller use the layout from it's parent module (not the root layout and not the current).


Hope this helps.
0

#6 User is offline   sarveshb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 06-April 11
  • Location:India

Posted 24 June 2011 - 11:20 AM

Simple [but not a proper way] to do this
1. First create class which will extend to Controller class of yii like
class MyController extends Controller {

public $layout = 'application.modules.admin.views.layouts.main';
}
2. then extends each controller of admin modules & it's child modules to these class,
So u will have the one layout for all admin panel.
2

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users