1

There is also have a question same as mine. However, there is still more thing I really don't understand, because when you develop module, all of them use MVC architecture. But at the same time, there are people still said that Magento 2 follow MVVM. So, what architecture that Magentro 2 use?

2
2

Magento 2 is a Model View ViewModel System and no more a design structured by MVC. The MVC model was incorporated in the previous version and seems to be quite similar to MVVM, but MVVM is a way more rich in dividing the View and Model in an application.

MVVM has three layers that include Model, View, and ViewModel. The business logic of an extension or application is represented as Model, whereas front-end is represented by the View. Just like the way Controllers serve as a mediator in an MVC model, the ViewModel bridges the gap between the Model and View in an MVVM system.

An extension developed for Magento 2 is said to consist of the basic design elements that are discussed above. Whereas, the role of controllers is not fully removed from Magento 2 as it is made responsible for managing the user flow that includes communicating the system about users’ requests.

Let me explain the same with the help of an example. For the sake of an example, you can try setting up a new URL and creating a phtml template for it. When you request a new URL in Magento 2, like http://magento.abc.com/hi/friend the MVVM system will send the request to a controller to process it just like the way it is done in MVC. But, there is a major difference in the responsibility of the controller in MVVM. It is held responsible for

Determining the page layout to select
Managing to preserve the data from user requests
And, either communicate the system to respond with HTTP, or
Direct users to next or previous page

Setting up an example URL will help you notice that not a single variable gets mentioned in the View because each View component is held responsible to derive data or information itself from the model layer, object, or an external source. The MVVM makes Magento split an HTML page into multiple sections that are called as containers. These containers possess blocks that are connected through a tree-like structure. The blocks further include a phtml template file.

The Magento block object serves as a ViewModel if you speak specifically about the MVVM system. The object block is capable of scanning and reading the business models, user requests, acquiring data from external system, etc. the template file is termed as View that solely collaborates with the block object that is the View Model

For more detail refer: https://weblizar.com/blog/magento-2-is-model-view-view-model-system-and-not-mvc-explained/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.