Hello,
Here is a sample code from my projects. I tested and it works.
plugin file code:
class My_Plugin_ChangeModuleLayout extends
Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract
$request)
{
$module = $request->getModuleName();
if ($module == 'admin') {
Zend_Layout::getMvcInstance()->setLayout('layout.admin');
}
}
}
bootstrap code:
protected function _initPlugins()
{
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin(new
My_Plugin_ChangeModuleLayout());
}
Here is the pastebin link of the same code:
http://pastebin.com/m62bd23b1
scs
On Wed, Nov 4, 2009 at 1:57 AM, Brenton Alker <[email protected]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Simeon Goranov wrote:
>> Hello,
>> I've got a module bootstrap file Admin_Bootstrap where the module is
>> "admin". I'm wondering how to change the default layout, which in my
>> case is layout.phtml only for the admin module. In my opinion I have to
>> do it into the bootstrap file, because in this way the change will
>> affect all of the module controllers. Do you have any idea how to solve
>> the problem ?
>
> You can't do it in your bootstrap as has been suggested by others. The
> bootstrap for *all* modules is run for *all* requests; even if the
> default module is requested, the admin bootstrap is still run. At the
> bootstrap stage routing has not yet been done, so the module being
> requested has not yet been determined. So, if you change the layout in
> any bootstrap it will be changed for every module.
>
> The most common solution I've seen to this is to use a pre-dispatch
> front controller plugins or action helper. Both of these will allow you
> to check the current request after routing and take the necessary steps
> to change the layout.
>
> - --
>
> Brenton Alker
> PHP Developer - Brisbane, Australia
>
> http://blog.tekerson.com/
> http://twitter.com/tekerson
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkrww2MACgkQ7bkAtAithus/rACfekgNOHJGmuOtuSC1UjFwMYLY
> GuQAniCsI0NM2PMTB7UbxPQtL8euVcIV
> =f7m9
> -----END PGP SIGNATURE-----
>