In Yii PHP framework, one has ability to create modules. As per Yii's official documentation here is definition of the module:
在Yii PHP框架中,人们可以创建模块。根据Yii的官方文档,这里是模块的定义:
A module is a self-contained software unit that consists of models, views, controllers and other supporting components. In many aspects, a module is similar to an application. The main difference is that a module cannot be deployed alone and it must reside inside of an application. Users can access the controllers in a module like they do with normal application controllers.
模块是一个独立的软件单元,由模型,视图,控制器和其他支持组件组成。在许多方面,模块类似于应用程序。主要区别在于模块不能单独部署,并且必须驻留在应用程序内部。用户可以像访问普通应用程序控制器一样访问模块中的控制器。
Let's say we have a huge aplication and we have to create front-end and backend. In this case, is it better to create frontend module
, and backend module
and use them, or it is better to implment frontend as one Yii application, and backend as second Yii application.
假设我们有一个巨大的应用,我们必须创建前端和后端。在这种情况下,最好是创建前端模块和后端模块并使用它们,或者最好将前端作为一个Yii应用程序,并将后端作为第二个Yii应用程序。
I'm asking this because if you look at Yii's 2 advance template, there three are different applications (common, backend, frontend
), but they are not implemented as three different modules, and my question is why?
我问这个是因为如果你看看Yii的2个高级模板,有三个是不同的应用程序(常见,后端,前端),但它们并没有实现为三个不同的模块,我的问题是为什么?
Is app is going to be slower when you use modules and what are pros and cons of using modules?
当您使用模块时,应用程序会变慢吗?使用模块的优缺点是什么?
2 个解决方案
#1
Yii2 advance template has 3 different applications however they are frontend, backend and console (not common).
Yii2高级模板有3个不同的应用程序,但它们是前端,后端和控制台(不常见)。
is it better to create frontend module, and backend module and use them?
创建前端模块和后端模块并使用它们会更好吗?
The answer is "it depends". Lets take some examples:
答案是“它取决于”。让我们举一些例子:
- I have a "users" section in the backend that tells the system what can each user change in the backend. I use this in multiple applications with no change at all so I have created a user module that I can just insert wherever I want. It is the simplest module because I never use it for the frontend.
- a blog module, the blog module is a little more complicated as it has a place to manage the blog (this part is in the backend) and the posts and comments shown in the front section (this part should be in the frontend). However I still want to be able to plug it in multiple applications. My solution was to create some folders in the actual module (I actually created the same structure frontend / backend / common). The logic is the same, in my website frontend I use what you find in the frontend folder of the module, the common holds the things that I use in both the frontend and backend (like some models) etc. Different application will use the same frontend controllers / widgets but make sure you allow the views to be changed.
我在后端有一个“用户”部分,告诉系统每个用户在后端可以更改什么。我在多个应用程序中使用它而没有任何变化,因此我创建了一个用户模块,我可以在任何地方插入。这是最简单的模块,因为我从不将它用于前端。
博客模块,博客模块稍微复杂一点,因为它有一个管理博客的地方(这部分在后端),前面部分显示的帖子和评论(这部分应该在前端)。但是我仍然希望能够将它插入多个应用程序中。我的解决方案是在实际模块中创建一些文件夹(我实际上创建了相同的结构前端/后端/公共)。逻辑是一样的,在我的网站前端我使用你在模块的前端文件夹中找到的东西,常见的东西包含我在前端和后端使用的东西(比如某些模型)等。不同的应用程序将使用相同的前端控制器/小部件,但请确保您允许更改视图。
The answer to use or not to use modules is actually the same answer to "Will I use this in other applications and can it function without the rest of the application?" A module should NOT be tight coupled with the rest of the application.
使用或不使用模块的答案实际上是“我将在其他应用程序中使用它并且它可以在没有其他应用程序的情况下运行吗?”的相同答案。模块不应与应用程序的其余部分紧密耦合。
#2
The idea of the modules in that they almost autonomous. At the stage of application development you must highlight from it all stand-alone elements. For example, I have a large CRM. I need a user module (includes all models associated with the user, controllers, display components and their configuration - for example the rules of routes). There is also an administrative module. There CRM module and a module for corporate events and meetings schedules. And about 3-5 independent modules - for example internal communications module,access control module and module of electronic payments. The convenience is that the all modules are self-contained. They have their own MVC- sets, sets of widgets and configurations. And they can be moved from one project to another without much effort.
模块的概念在于它们几乎是自主的。在应用程序开发阶段,您必须从中突出显示所有独立元素。例如,我有一个大型CRM。我需要一个用户模块(包括与用户,控制器,显示组件及其配置相关的所有模型 - 例如路线规则)。还有一个管理模块。有CRM模块和公司活动和会议日程安排的模块。大约3-5个独立模块 - 例如内部通信模块,访问控制模块和电子支付模块。方便的是所有模块都是独立的。他们有自己的MVC集,小部件和配置集。他们可以毫不费力地从一个项目转移到另一个项目。
Here's another interesting modular system: There are resource with various functionality. It can be divided into modules. Each module file should implement a modular interface (you need to write it). For example, I want each module to provide its own widget for menu.(Drop-down list or just a button) and its own widget for dashboard. Also in the module file specified access to various actions, etc.
这是另一个有趣的模块化系统:有各种功能的资源。它可以分为模块。每个模块文件都应该实现模块化接口(您需要编写它)。例如,我希望每个模块都为菜单提供自己的小部件。(下拉列表或只是一个按钮)和它自己的仪表板小部件。另外在模块文件中指定访问各种动作等。
There is a basic component,that prior to the step of rendering polls all modules at their regulated functionality and builds on its basis the menu, dashboard and other widgets. The main thing with this approach, keep in mind, that everything that module provides must be prepared by the modular functionality(models, widgets) not to disrupt the modular autonomy.
有一个基本组件,在渲染步骤之前,轮询所有模块的规则功能,并在其基础上构建菜单,仪表板和其他小部件。这种方法的主要内容,请记住,模块提供的所有内容必须由模块化功能(模型,小部件)准备,而不是破坏模块化自治。
#1
Yii2 advance template has 3 different applications however they are frontend, backend and console (not common).
Yii2高级模板有3个不同的应用程序,但它们是前端,后端和控制台(不常见)。
is it better to create frontend module, and backend module and use them?
创建前端模块和后端模块并使用它们会更好吗?
The answer is "it depends". Lets take some examples:
答案是“它取决于”。让我们举一些例子:
- I have a "users" section in the backend that tells the system what can each user change in the backend. I use this in multiple applications with no change at all so I have created a user module that I can just insert wherever I want. It is the simplest module because I never use it for the frontend.
- a blog module, the blog module is a little more complicated as it has a place to manage the blog (this part is in the backend) and the posts and comments shown in the front section (this part should be in the frontend). However I still want to be able to plug it in multiple applications. My solution was to create some folders in the actual module (I actually created the same structure frontend / backend / common). The logic is the same, in my website frontend I use what you find in the frontend folder of the module, the common holds the things that I use in both the frontend and backend (like some models) etc. Different application will use the same frontend controllers / widgets but make sure you allow the views to be changed.
我在后端有一个“用户”部分,告诉系统每个用户在后端可以更改什么。我在多个应用程序中使用它而没有任何变化,因此我创建了一个用户模块,我可以在任何地方插入。这是最简单的模块,因为我从不将它用于前端。
博客模块,博客模块稍微复杂一点,因为它有一个管理博客的地方(这部分在后端),前面部分显示的帖子和评论(这部分应该在前端)。但是我仍然希望能够将它插入多个应用程序中。我的解决方案是在实际模块中创建一些文件夹(我实际上创建了相同的结构前端/后端/公共)。逻辑是一样的,在我的网站前端我使用你在模块的前端文件夹中找到的东西,常见的东西包含我在前端和后端使用的东西(比如某些模型)等。不同的应用程序将使用相同的前端控制器/小部件,但请确保您允许更改视图。
The answer to use or not to use modules is actually the same answer to "Will I use this in other applications and can it function without the rest of the application?" A module should NOT be tight coupled with the rest of the application.
使用或不使用模块的答案实际上是“我将在其他应用程序中使用它并且它可以在没有其他应用程序的情况下运行吗?”的相同答案。模块不应与应用程序的其余部分紧密耦合。
#2
The idea of the modules in that they almost autonomous. At the stage of application development you must highlight from it all stand-alone elements. For example, I have a large CRM. I need a user module (includes all models associated with the user, controllers, display components and their configuration - for example the rules of routes). There is also an administrative module. There CRM module and a module for corporate events and meetings schedules. And about 3-5 independent modules - for example internal communications module,access control module and module of electronic payments. The convenience is that the all modules are self-contained. They have their own MVC- sets, sets of widgets and configurations. And they can be moved from one project to another without much effort.
模块的概念在于它们几乎是自主的。在应用程序开发阶段,您必须从中突出显示所有独立元素。例如,我有一个大型CRM。我需要一个用户模块(包括与用户,控制器,显示组件及其配置相关的所有模型 - 例如路线规则)。还有一个管理模块。有CRM模块和公司活动和会议日程安排的模块。大约3-5个独立模块 - 例如内部通信模块,访问控制模块和电子支付模块。方便的是所有模块都是独立的。他们有自己的MVC集,小部件和配置集。他们可以毫不费力地从一个项目转移到另一个项目。
Here's another interesting modular system: There are resource with various functionality. It can be divided into modules. Each module file should implement a modular interface (you need to write it). For example, I want each module to provide its own widget for menu.(Drop-down list or just a button) and its own widget for dashboard. Also in the module file specified access to various actions, etc.
这是另一个有趣的模块化系统:有各种功能的资源。它可以分为模块。每个模块文件都应该实现模块化接口(您需要编写它)。例如,我希望每个模块都为菜单提供自己的小部件。(下拉列表或只是一个按钮)和它自己的仪表板小部件。另外在模块文件中指定访问各种动作等。
There is a basic component,that prior to the step of rendering polls all modules at their regulated functionality and builds on its basis the menu, dashboard and other widgets. The main thing with this approach, keep in mind, that everything that module provides must be prepared by the modular functionality(models, widgets) not to disrupt the modular autonomy.
有一个基本组件,在渲染步骤之前,轮询所有模块的规则功能,并在其基础上构建菜单,仪表板和其他小部件。这种方法的主要内容,请记住,模块提供的所有内容必须由模块化功能(模型,小部件)准备,而不是破坏模块化自治。