-- Sergio Rinaudo <[email protected]> wrote
(on Thursday, 07 May 2009, 10:49 PM +0200):
> I added the line you said, and the layout is switched, but
> unfortunatelly for all modules, so also the default module is rendered
> with the admin layout. Any advice?
Okay, I understand better now what you're trying to do -- you want a
different layout based on which module was selected during routing.
In this case, you can't make this determination during bootstrapping
because routing hasn't yet happened. What you need to do is create a
*plugin* that runs at either routeShutdown() or dispatchLoopStartup(),
and selects the layout based on the current module.
At its simplest, this plugin would look like the following:
My_Plugin_LayoutSwitch extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$layout =
Zend_Controller_Action_HelperBroker::getStaticHelper('layout');
$module = $request->getModuleName();
if ('default' != $module) {
$layout->setLayout($module);
}
}
}
Register that from your application bootstrap, and you should be set.
You may need to tweak it -- if not all modules have a unique layout, for
instance, you may need to add some more logic in there.
> > Date: Thu, 7 May 2009 16:18:44 -0400
> > From: [email protected]
> > To: [email protected]
> > Subject: Re: [fw-general] ZF1.8 Switching layouts between modules.
> >
> > -- Sergio Rinaudo <[email protected]> wrote
> > (on Thursday, 07 May 2009, 08:54 PM +0200):
> > > I've almost completed to implement all my past work in the new
> > > Zend_Application, I still have the problem on how switch layouts between
> > > modules. I noticed here you can specify this in the configuration ini
> > > file:
> > >
> > > http://framework.zend.com/manual/en/
> zend.application.available-resources.html#
> > > zend.application.available-resources.modules.configExample
> > >
> > > but if I add this line on my ini
> > >
> > > admin.resources.layout.layout = "admin"
> > >
> > > I get the error
> > >
> > > Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception'
> > > with
> > > message 'Resource matching "frontcontroller" not found' in
> >
> > I know what's happening here.
> >
> > The layout resource has this:
> >
> > $this->getBootstrap()->bootstrap('FrontController');
> >
> > The problem is that your _module_ bootstrap doesn't have the resources
> > that the _application_ bootstrap had -- and so it's finding no matching
> > resource to bootstrap.
> >
> > One workaround is to add this to your configuration:
> >
> > admin.resources.frontController[] =
> >
> > This will grab and return the front controller singleton, which should
> > work for these purposes.
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead | [email protected]
> > Zend Framework | http://framework.zend.com/
>
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> Cerchi i tuoi spazi? Hotmail va oltre i 5GB. Scopri perch !
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/