Thank you for your reply Matthew. I appreciate the time you give to the
community.
I have seen no reference to stack indexes in the reference guide before. I
assume when registering a plugin with a stack index of 1 it is run before
another plugin that has been registered with a stack index of 10? I also
assume that certain plugins are assigned default stack indexes? Am I to
believe that the default ErrorController is registered with 99 by default?
Im using both a Zend_Layout pluginClass to change layout based on module but
I am also using a plugin to set the error controller to that of the current
module as well.
Here is the plugin to overide the error controller module:
class MyApp_Controller_Plugin_OverideErrorModule extends
Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract
$request)
{
$module = $request->getModuleName();
$errorHandler =
Zend_Controller_Front::getInstance()->getPlugin('Zend_Controller_Plugin_ErrorHandler');
$errorHandler->setErrorHandlerModule($module);
}
}
This is registered in my bootstrap:
self::$frontController->registerPlugin(new
MyApp_Controller_Plugin_OverideErrorModule());
My layout plugin (as posted previously) is registered in my bootstrap as
follows:
Zend_Layout::startMvc(
array(
'layoutPath' => $root . '/app/views/layouts',
'layout' => 'layout',
'pluginClass' => 'MyApp_Layout_Controller_Plugin_Layout'
)
);
If I set the stack index of OverideErrorModule plugin above to 99 I get the
following error:
Fatal error: Uncaught exception 'Zend_Controller_Exception' with message
'Plugin with stackIndex "99" already registered'
If you meant I should set the stack index on the Layout plugin how would I
do so in the startMvc context? I believe this already registers with a late
stack index by default?
To remind you.. my problem is that when the errorController is called within
a module (http://my.app/module-name/does-not-exist) the path to the layout
is generated incorrectly due to the preDispatch being called twice like so:
"Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script
'module1.phtml' not found in path
(/my_app/app/modules/module1/modules/module1/views/layouts/"
Note that /my_app/app/modules/module1/modules/module1/views/layouts/ should
be /my_app/app/modules/module1/views/layouts/...
Thanks again. :)
Matthew Weier O'Phinney-3 wrote:
>
> -- drj201 <[EMAIL PROTECTED]> wrote
> (on Saturday, 25 October 2008, 06:48 AM -0700):
>>
>> Can someone please confirm if this is the expected behaviour please or
>> simply
>> if I am doing something wrong? Thanks. :)
>
> If you look at how Zend_Layout registers its plugin, you'll see that it
> uses a particular plugin index to ensure that that it plays well with
> the error handler:
>
> $front->registerPlugin(new $pluginClass($this), 99);
>
> Register your custom plugin with that same index, and you should be
> fine.
>
>
>> drj201 wrote:
>> >
>> > I have a front controller plugin to override the default behavior of
>> > Zend_Layout via Zend_Layout::startMvc like so:
>> >
>> > class MyApp_Layout_Controller_Plugin_Layout extends
>> > Zend_Layout_Controller_Plugin_Layout
>> > {
>> >
>> > public function preDispatch(Zend_Controller_Request_Abstract
>> $request)
>> > {
>> >
>> > switch ($request->getModuleName())
>> > {
>> > case 'admin':
>> > $this->_moduleChange('admin');
>> > break;
>> > case 'module2':
>> > $this->_moduleChange('module2');
>> > break;
>> > // Use default Layout
>> > }
>> > }
>> >
>> > protected function _moduleChange($moduleName)
>> > {
>> >
>> >
>> >
>> $this->getLayout()->setLayoutPath(dirname(dirname($this->getLayout()->getLayoutPath()))
>> > . DIRECTORY_SEPARATOR . 'modules/' . $moduleName . '/views/layouts');
>> > $this->getLayout()->setLayout($moduleName);
>> >
>> > return;
>> > }
>> >
>> > }
>> >
>> > Im experiencing unexpected behaviour with the above and the use of
>> > modules. The above works fine for calls to
>> http://my-app/controller-name
>> > (controllers in the default directory) and works fine for modules (and
>> > their controllers) that exist i.e. http://my-app/module-name or
>> > http://my-app/module-name/controller-name.
>> >
>> > When navigating to http://my-app/does-not-exist or
>> > http://my-app/module-name/does-not-exist I am getting the wrong path
>> > returned in the setLayoutPath. It seems that when the Error Controller
>> is
>> > called the Zend_Layout::startMvc plugin is called again (calling the
>> > plugin on preDispatch twice builds an incorrect path to use for the
>> layout
>> > script)!
>> >
>> > Investigating further by simply echoing some text in the preDispatch
>> > function of the plugin (crude test I know) it appears that when
>> navigating
>> > to a path that does not exist (i.e. no controller) the text is echoed
>> > twice! Is this default behaviour i.e. when ErrorController is called so
>> is
>> > the plugin?
>> >
>> > Thanks in advance for any insight! However small!
>> >
>> > Regards,
>> >
>> > Dave
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Default-behavior-of-Zend_Layout%3A%3AstartMvc-and-plugin-use--tp20031977p20164288.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>
> --
> Matthew Weier O'Phinney
> Software Architect | [EMAIL PROTECTED]
> Zend Framework | http://framework.zend.com/
>
>
--
View this message in context:
http://www.nabble.com/Default-behavior-of-Zend_Layout%3A%3AstartMvc-and-plugin-use--tp20031977p20186096.html
Sent from the Zend Framework mailing list archive at Nabble.com.