The default dynamic module in the Zend Framework

Does anyone know how to dynamically install the default module in Zend Framework and not run namespace problems? For example, what I want to do is to have a table of modules that can be loaded, with one of them installed as the default module. For example, I might have:

admin blog calendar 

as modules that can be loaded. If I have a โ€œblogโ€ as the default module, then โ€œadminโ€ and โ€œcalendarโ€ should have their own controllers with names (Admin_IndexController, Calendar_IndexController), and โ€œblogโ€ should not (IndexController).

If I change the calendar to the default module, ZF will no longer be able to find classes due to the namespace.

How do you get around this? I am currently using the following code:

 $modules = new Modules(); $activeModules = $modules->fetchActive(); foreach($activeModules as $mod) { $loadedModules[$mod->name] = '..application/modules/' . $mod->name . '/controllers'; if($mod->default) { $defaultModule = $mod->name; } } $frontController->setControllerDirectory($loadedModules); $frontController->setDefaultModule($defaultModule); 
+7
php module zend-framework
source share
4 answers

If you plan to change the default module, it is probably best to use the ALL namespaces, and then indicate that the default module should have a prefix:

First, change the blog module to use the namespace:

 <?php // Used to be "class IndexController" class Blog_IndexController extends Zend_Controller_Action { } 

Then call setParam on the prefixDefaultModule option in your Zend_Controller_Front instance:

 <?php // Allow your default module to be prefixed $frontController->setParam('prefixDefaultModule', true); 

For an explanation see bug # 1831 .

+6
source share

use application.ini: resources.frontController.prefixDefaultModule = true resources.frontController.defaultModule = default

+4
source share

You can make the default module virtually the crucial part of the whole process. More specifically, to make all requests for the default module, go to the class, which will then determine which specific module is used by default by default and redirect the request to it.

At least the way we implemented it;)

+1
source share

It looks like the PreDispatch controller plugin works.

You can change the module change request based on a specific request or identification / session / known data to forward or redirect on demand.

0
source share

All Articles