For those who are new to learning, Magento is really complicated, it is the successor of Zend Framework with MVC (Model – View – Controller) architecture. This article will introduce you to an overview of the overall structure of Magento.
First, we will learn more about the overall structure of MVC and its role in Magento 2.
Model: classes that provide data, services related to data, and business logic. These classes work directly with the data and feed the data to other components. In Magento, these classes are stored in the Model folder.
View: classes that define how data is presented (not updated). These classes are stored in the folder Block, the template of the module.
Controller: is the layer that controls the application flow, it receives the input of the user’s requests through the HTTP header, forwards those requests to the layers in charge of directly handling the request. From the link, the router will find the Controller that controls the link. In Magento, these classes are located in the controller directory.
1. Directory structure in Magento
app / etc – directory that contains global configs
app / code – contains modules (models, controllers, helpers, blocks …)
app / code / core – modules developed by magento team
app / code / community – modules developed by the community
app / code / local – modules made by other developers
app / code / core / Mage – default namespace of magento
app / code / core / Mage / {Module} – module root
app / design – location of design packages (layouts, templates, translations included)
app / design / frontend – frontend design
app / design / {area} / {package} / {theme} – theme customizations
app / design / {area} / {package} / {theme} / layout – .xml files included
app / design / {area} / {package} / {theme} / template – .phtml templates
app / design / {area} / {package} / {theme} / locale – Zend_Translate compatible translation files for package / theme
app / locale – locale files
app / locale / {locale (en_US)} – Zend_Translate compatible translation files for modules
skin / {area} / {package} / {theme} / – css and images package included
lib – are libraries such as Zend and Varien
js – javascripts default in Magento 2
media – uploaded files
var – temporary files
includes – contains config.php
2. Modular structure in Magento 2
A module of Magento 2 will normally have the following main components:
Block: A place used to load data, adjust data from the database before displaying data in the template.
Controller: Receive requests from the user from HTTP and then pass the request to the handler layers.
Etc: includes XML files used to configure the module included:
– Config.xml: used to declare model, helper, block
– System.xml: config creates a number of fields, displayed on the left menu when you click on system/config.
– Adminhtml.xml: used to configure display on the main menu of the admin section.
Helper: This is used to write functions that are used in many different places in the system.
Model: Used to write the query directly to the database.
SQL: used to create tables, update data tables, interactively change data
Above are the basic knowledge about Magento 2 structure to help you get a better overview of Magento 2’s operating model. Hope this guide helps you!
If your website is having problems, please leave a comment below or contact us at Magepow Contact, the Magepow technician team will assist in solving your problem quickly. Thanks.
Hope this article will helpful for you!
Leave a Reply