Magento is a typical object-oriented PHP framework which is used to develop web applications that convert to form a full-fledged, fully functional and dynamic eCommerce web shopping cart. The powerful features provided by Magento range from placing an order, adding items to entering the payment gateway and completing the payment schedule.
In the case of Magento extension, you create a unique code which will help extend some functionality without interfering with the core codes. Let’s understand how this core and extension codes work simultaneously and how the Magento module structure looks like.
Magento Extensions: Basics
Before moving on to understand the module structure in Magento, it is essential to understand the three kinds of Magento extensions that are present.
- The Core Extension: Magento particularly develops this. It is available by default. You generally don’t make any changes in here.
- The Community Extension: Magento community is where the open source Magento source is available. Here the community developers come up with various extensions that are available for free.
- The Local Extension: There is an absolute need that you can fulfil using an extension. This is where the local extension comes to use. You will see that local extensions are either developed by the third party or by you to complete a specific task.
Magento Module Structure
The module structure for Magento begins with Namespace. This is the Magento directory that is present above your extension. Let’s say it is the category of extension or in other words the main class that contains the extension. So, in a way, the module structure begins with NameSpace. Most people use their company name in place of the Namespace to define the category of extension.
Now the MVC structure of Magento has a few predefined blocks that you need to understand. It helps to understand why each block is present and how it is useful to you.
- Controller: In any normal MVC structure, the controller is a class that controls the overall logical flow and presentation of the Magento layout and functioning. It is a class which you need to create using the PHP extension. Generally, the name format is indexcontroller.php. A controller in general is used as the prefix in most cases.
- Action: Let’s say action is the function of a controller in a standard MVC structure. Any work that is performed by the module or the extension when translated to the outside would be considered as the function of the controller.
- Block: This is what you view when you are considering a typical Magento store. Blocks will coordinate with the models to give out a view format for the store.
- Helper: All the utility functions that are typically needed by block, view and other extensions would be stored in this module called helper. It can be called anywhere at any point by the system.
- Model: This is the main folder in your Magento coding. This is where your business logic is stored and handled. Object Relation Mapper is utilized to build Magento codes. It loads the database field using PHP magic function.
- SQL: If you are planning to install or upgrade a particular model, SQL custom handle comes to your rescue. You will need to create a MySQL folder while installing your module or extension.
The Flow of Code Execution
Before you begin understanding how the code is executed, it is very important to know how each request Magento receives is being served from its quarters. This will help you understand how Magento works.
There is a .htaccess file in the root directory. This is where the routing of every request is defined correctly. A few rewrite rule help establish the right path of the claims. In case of the rewrite command, there would be an explanation as to why it has been used and how it will be used further.
Let’s say a request comes which has no file or directory support; then the rewrite command will route it forward. In case, your command defines a directory name which cannot be identified, in such a case the request will be routed to the index file. Here, at the index file, your command will be routed to the specific destination.
The next step is to understand how libraries are loaded on to Magento. Firstly, you need to remember that whatever requests come to Magento, are first routed to the index file. In case a suitable category is found at the index, it is routed forward else an error is declared.
In the first case, a suitable category is found, the Magento file checks for maintenance flag. In case of Maintenance, file is loaded, it will include the Mage app which is a very important code file for the Magento website. Mage performs all the loading actions for library and other related modules.
Next, once the Mage.php is loaded, the file checks for developer mode, whether it is enabled or disabled. In case it is enabled, the Mage.php will run, which happens to be the main entry point for the Magento files and library modules are loaded.
Once, the library is loaded. Further, the codes are executed as per the MVC structure which has been defined at the earlier stage.
M-Connect Media, leading Magento extension development company Feel free to contact us for any custom requirement!