K
K
Konstantin2019-10-24 17:44:56
Yii
Konstantin, 2019-10-24 17:44:56

What is the point of modules in Yii2?

Hello. Connoisseurs of yii2, please tell me what is the meaning of modules in the framework? It is clear that the documentation says that this is something isolated that can be used independently in another place.
I'm at a loss for a choice. Where is it better to store modules in the common folder or in the current backend or frontend section if you build a site on modules. I usually build on controllers, where the url looks like controller/action. But I want to start collecting correctly. What is the benefit of using modules?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2019-10-24
@small_jedi

As written in the documentation:

Modules are complete software blocks made up of models, views, controllers, and other supporting components. When modules are installed in an application, the end user gets access to their controllers. For this reason, modules are often viewed as miniature applications. Unlike applications, modules cannot be deployed separately. Modules must be inside applications.

Based on the definition, Modules (microservices) exist to isolate different parts of the site from each other. Due to the weak coupling and conjugation of the Module , you can change one part of the site for another without breaking others. At the same time, it should be taken into account that the database of such modules must also be independent, and such modules communicate with each other through the API or application events when the modules are on the same server.
If one module breaks, the whole application does not break . On this topic, you can read the article How to design a stool? . I once answered a similar topic on Toster.
You can come up with the architecture of the Modules in the application yourself. The main thing is that the domain layer should be independent . Under modules, you can make a separate root folder with the name of the module :
- Backend
- Frontend
- Shop
- Blog

Or to group:
- Backend
- Frontend
- Modules
- Modules/Shop
- Modules/Blog

The controllers and the view will simply be separated into module folders:
- Backend/Controller/Shop
- Backend/Controller/Blog
- Frontend/Controller/Shop
- Frontend/Controller/Blog

Например,
so or so . Separation in Models divide everything into module folders:
Model/Shop
Model/Blog

To summarize:
1. The module serves to isolate individual parts of the application into different parts. If the engine breaks down, the chassis will not break. The chassis can be changed to a chassis from another car, while the engine does not care what chassis the car is on.
2. The module can be reused in other projects or placed in a separate repository and included in composer .
3. Well-structured, readable and understandable code. Maintainability.
4. Testability
5. Horizontal scaling.
and others.
Separation of modules takes place in folders following the PSR7 standards .
Useful articles on a similar topic:
1.https://toster.ru/q/659155
2. My question on the forum
3. Organization of independent modules on Yii2

S
Sanes, 2019-10-24
@Sanes

Well, you understand everything correctly. Module, something independent. Possibly with dependencies. Typically used to organize a codebase.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question