Phalcon Multi module - Dynamic Module registration

白昼怎懂夜的黑 提交于 2020-01-02 10:08:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!