简体   繁体   English

创建具有多个子模块的扩展

[英]Create extension with multiple submodules

I'd like to create an extension (module) that includes a modification of the base system, and also includes two separate modules that can be placed in layouts.我想创建一个扩展(模块),其中包括对基本系统的修改,还包括两个可以放置在布局中的独立模块。 Both of these single instance modules depend on this modification.这两个单实例模块都依赖于此修改。

With multi instance modules you can create multiple instances of a module who all share the same controllers and views.使用多实例模块,您可以创建一个模块的多个实例,它们都共享相同的控制器和视图。

Is there a way to have one base module install other modules that are then inserted as children of said base module, share the same admin controller / model, but different catalog controller / views?有没有办法让一个基本模块安装其他模块,然后作为所述基本模块的子模块插入,共享相同的管理员 controller / model,但不同的目录 Z594C103F2C6E04C3D8AB059F031E0C1 视图?

Uninstalling the base module should lead to uninstalling the child modules as well.卸载基本模块也会导致卸载子模块。

You can achieve this by creating Model, View, Controller and Language files for the installable module.您可以通过为可安装模块创建 Model、View、Controller 和语言文件来实现此目的。 Let's call it the Main module .我们称它为Main module

Then you can create models, controllers and views for the sub-modules and load them into the Main Controller.然后您可以为sub-modules创建模型、控制器和视图,并将它们加载到主 Controller 中。

Example:例子:

class ControllerExtensionModuleMainModule extends Controller {
    public function install() {
        $this->load->model('extension/module/MainModule');

        /**
         * Load submodule's model into the Main's module controller
         */
        $this->load->model('extension/module/SubModule');


        $this->model_extension_module_MainModule->install();

        /**
         * Execute install function that exists in Submodel (submodule)
         */
        $this->model_extension_module_SubModule->install();
    }
}

Using this approach you can create many "sub-modules" and install or uninstall them all together at the same time.使用这种方法,您可以创建许多“子模块”并同时安装或卸载它们。

Note: Try to organize your classes and functions or else you will create an untangleable mess.注意:尝试组织你的类和函数,否则你会造成无法解决的混乱。 Also keep always in mind the "Single Responsibility" principle.还要始终牢记“单一职责”原则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM