Phalcon Multi模块-动态模块注册 [英] Phalcon Multi module - Dynamic Module registration
问题描述
大家好,我在Phalcon的多模块项目中使用以下结构
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]
我在我的引导程序index.php文件中仅注册了模块1和模块2.像这样:
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'
)
));
现在,我的默认模块是Module 1.如何使用模块n的控制器(此模块尚未注册).有没有动态的模块注册方式?
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?
推荐答案
基本上,您应该避免在另一个模块中使用一个模块控制器.这不是应用程序行为的正确方法;)这更多是关于一般的良好编程和设计模式,而不是Phalcon本身.例如,您可以使用 http://en.wikipedia.org/wiki/Service-oriented_architecture
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
可以动态注册服务并在模块之间共享它们,如果您想在Phalcon中实现,则可以查看Vegas CMF:
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
这篇关于Phalcon Multi模块-动态模块注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!