views:

652

answers:

3

I have two modules, default and mojo.
After the initial bootstraping code which is the same for both of the modules, I want, for example, to use different layouts for each module (Or use different credentials check etc).
Where do I put this: IF(module=='mojo') do this ELSE do that

+1  A: 

hmm i havent tried this

http://www.nabble.com/Quick-Guide-How-to-use-different-Layouts-for-each-module-to23443422.html#a24002073

the way i did that now was thru a front controller plugin

something like

switch ($request->getModuleName()) {
   case "": 
      // set layout ...
}
iceangel89
+3  A: 

If you are using Zend_Application (in ZF1.8) then you should be able to use the module specific configuration options to provide this functionality with a as explained in the relevant section in the documentation.

This would require you to set the layout in the config so it looked something like

mojo.resources.layout.layout = "mojo"

anothermodule.resources.layout.layout = "anotherlayout"

The layout would then be set automatically by the bootstrap.

The other alternative is to use a front controller plug-in that implements the preDispatch() method to set the layout based on the module name.

Tim Wardle
+1 this seems much simpler than my answer :) but where will the layoutname.phtml file go? modulename/layouts? or defaultmodule/layouts?
iceangel89
It can go in either place. If you want it in the module's directory then use the module autoloader to add the module as another namespace.
Tim Wardle
Has anyone tested this to work? From http://bit.ly/f3Ioc "One might think that prepending the second line with "default." will enable layouts specific to the module, but unfortunately it doesn't. It will use the last specified template"
joedevon
A: 

Hi,

I've looked into the subject a couple of days ago, trying to get it to work on bootstrap config alone. The big problem is that all the bootstrap files are loaded, so it gives some weird results in which layout is used.

My conclusion was that you can have the config in place, but you need to work with FrontController plugins or ActionController helpers. If you want to use config set in the application.ini and you want to load the config trough the bootstrap, helpers is the only way to go. From the helper, you can then load the ActionController and on that execute the getInvokeArgs to load the bootstrap. A lot of hastle... :)

Anyway, I've done a small implementation as an example in a blog post: http://blog.keppens.biz/2009/06/create-modular-application-with-zend.html

Goodluck,

Jeroen

tnx, the link iceangel89 (accepted answer) gave me was very straight forward and simple to implement.
Itay Moav