问题
Hi guys Im using the following structure for a multi-module project in Phalcon
[modules]
[module1]
[controllers]
[models]
[views]
[module2]
[controllers]
[models]
[views]
[module-n]
[controllers]
[models]
[views]
I have registered only Module 1 and Module 2 in my bootstrap index.php file. Like this:
$this->registerModules(array
(
'Module1' => array(
'className' => 'Modules\Module1\Module',
'path' => '../modules/module1/Module.php'
),
'Module2' => array(
'className' => 'Modules\Module2\Module',
'path' => '../modules/module2/Module.php'
)
));
Now, my default module is Module 1 . How do i use Controllers of module n(this module has not been registered). Is there any dynamic way of registering modules?
回答1:
Basically you should avoid using one module controller in another module. This is not a correct way for application to behave ;) This is more about general good programming and design patterns, not the phalcon itself. You can for example use http://en.wikipedia.org/wiki/Service-oriented_architecture
There is possibility to register services dynamically and share them between modules, if you are looking for implementation in Phalcon, you can check Vegas CMF: http://vegas-cmf.github.io/1.0/guide/di/service-manager.html
来源:https://stackoverflow.com/questions/25033503/phalcon-multi-module-dynamic-module-registration