Page 1 of 1

[Zend] Modules and module specific Bootstrap

Posted: Tue Apr 19, 2011 5:25 pm
by VladSun
I have had the module directory structure in my application folder. I have put the specific module related options in my application.ini (multilanguage support):
[text]resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = On

resources.router.routes.defaultmodule.type = Zend_Controller_Router_Route_Module
resources.router.routes.defaultmodule.abstract = On
resources.router.routes.defaultmodule.defaults.module = "default"

resources.router.routes.language.type = Zend_Controller_Router_Route
resources.router.routes.language.route = ":language"
resources.router.routes.language.reqs.language = "^(bg|en)$"
resources.router.routes.language.defaults.language = "bg"

resources.router.routes.default.type = Zend_Controller_Router_Route_Chain
resources.router.routes.default.chain = "language, defaultmodule"[/text]

I have put the Bootstrap.php (extends Zend_Application_Module_Bootstrap) files in each of my modules root directories.

I've read that even I had made this, *every* single module Bootstrap file will be executed after the application Bootstrap (very annoying).

Question: how to distinguish in my module Bootstrap files the action controller of which module is about to be executed, so I can take different actions in them?

Re: [Zend] Modules and module specific Bootstrap

Posted: Thu Apr 21, 2011 5:51 am
by VladSun
A dirty solution...

Code: Select all

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	
	protected function _initModuleDiscovery()
	{
		$this->bootstrap('frontcontroller');
		$front = $this->getResource('frontcontroller');
		
		$front->currentModule = array_pop(explode('/', $front->getModuleDirectory()));
	}
and

Code: Select all

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
	protected function _initApplication()
	{
		$this->bootstrap('frontcontroller');
		$front = $this->getResource('frontcontroller');

		echo $front->currentModule;
	}
}
There is a protected property in the Dispatcher, but no getter ... :(

[text]object(Zend_Controller_Dispatcher_Standard)[18]
protected '_curDirectory' => null
protected '_curModule' => string 'admin' (length=7)[/text]

Re: [Zend] Modules and module specific Bootstrap

Posted: Thu May 05, 2011 5:31 am
by VladSun
I think what I did was wrong in general. Maybe I've been misled by users' comments about using Zend Modules for having multiple web sites /parts(e.g. the Admin backend panel and web site frontend). In my understanding, Zend Modules are used for reusable parts (modules) of a single application and not for defining/implementing multiple applications. The "default" module (i.e. the main application) should reside in the root directory, while the reusable parts are put into the "modules" (e.g.) directory. So, having every module Bootstrap executed after the "main" application Bootstrap is a good thing and it's a must.

That's the way I see it.

Re: [Zend] Modules and module specific Bootstrap

Posted: Thu May 05, 2011 10:06 am
by John Cartwright
I would disagree with your your last comments. Modules are a perfect candadate for standalone applications, although more often then not modules will share common library functionality so it doesn't necessarily end up that way.

I've also sent you a PM.

Re: [Zend] Modules and module specific Bootstrap

Posted: Thu May 05, 2011 1:53 pm
by VladSun
I agree and disagree - every module, including the default module should be a good candidate for a standalone application. I think, the way Zaend wanted it, was to have these applications as reusable parts - that's why the default module Bootstrap is executed first (so it can set up the enviroment for other modules e.g.)

http://imgur.com/FbPFQ.png