In my opinion, using a plugin has some advantages:
- It's more portable: you don't have to copy-paste specific lines from
modules' base controllers if you want the same functionality in other
applications/projects. Matthew also seems to put an effort in making people
not use base controllers for such "helper" features, exactly for this
reason.
- It's cleaner: you keep all your logic for switching layouts in one place.
Indeed this particular plugin could have more advanced features for setting
it up and configuring it, which would make it even more portable.
- It's easier to disable this feature if you want to (e.g. debugging), by
just not registering it in the bootstrap, or unregistering it.
I thought I had more, but maybe i really didn't. Anyway, don't take it from
me -- I don't even use multiple layouts :) I tend to keep my one layout
generic/lightweight and use view helpers for most of my configurable
presentation stuff. Then again, I haven't really made any huge apps in ZF
yet.
Robin
On Wed, Apr 23, 2008 at 10:46 PM, Eric Coleman <[EMAIL PROTECTED]> wrote:
> I'm not sure if this is right or wrong, but basically, I create a layout
> instance in my bootstrap and set it to disabled..
>
> Then, each modules has it's own abstract controller, and I use the init()
> method of there to specify the layout for the module. Is this not something
> I should be doing, and should instead be leaving to a plugin like you did
> below? I used to use that method but found the init() method above better
> (can't remember why though)...
>
> Best Regards,
> Eric
>
>
> On Apr 23, 2008, at 2:42 PM, Robin Skoglund wrote:
>
> > I'd consider writing a postDispatch plugin, so you know what module
> > you're
> > actually dispatching. Something like:
> >
> > class My_Controller_Plugin_ModuleLayout extends
> > Zend_Controller_Plugin_Abstract
> > {
> > public function postDispatch(Zend_Controller_Request_Abstract
> > $request)
> > {
> > $layout = Zend_Layout::getMvcInstance();
> > $module = $request->getModuleName();
> > $layout->setLayout($module);
> > }
> > }
> >
> > Then in your bootstrap you do $front->registerPlugin(new
> > My_Controller_Plugin_ModuleLayout()).
> >
> > Of course, you could also do something more specific, e.g. limiting to
> > only
> > a few layouts and use a switch-case. Endless possibilites. This should
> > also
> > be a quite portable way of doing things.
> >
> > Robin
> >
> > On Wed, Apr 23, 2008 at 8:09 PM, rollockg <
> > [EMAIL PROTECTED]> wrote:
> >
> >
> > > Is there a way to define in my bootstrap a separate layout path for
> > > each
> > > module?
> > > --
> > > View this message in context:
> > >
> > > http://www.nabble.com/Alternate-layouts-by-module-tp16834740p16834740.html
> > > Sent from the Zend Framework mailing list archive at Nabble.com.
> > >
> > >
> > >
>