The module is an independent component. It is logical to the group – that contains blocks, controllers, helpers, models, etc – that are related to a specific business feature. It allows bringing additional features for the e-commerce store which is based on Magento 2.
Module are two locations where a module can be located in Magento 2
An app/code directory is the first location. This directory used for all custom and 3rd party modules.
A vendor directory is the second location. If you build an extension to be reused, it is better to use the composer to create it and put your module in this folder.
Let’s create a vendor directory inside the app/code/Vendor/ directory, let’s create a module directory.
There are two required files: registration.php and module.xml
– The registration.php file inside the app/code/Vendor/Module with the following code.
1 2 3 4 5 6 7 8 9 |
<?php use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register( ComponentRegistrar::MODULE, ‘Vendor_Module’, __DIR__ ); |
– The module.xml file inside the app/code/Vendor/Module/etc with the following code.
1 2 3 4 |
<?xml version=“1.0”?> <config xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=“urn:magento:framework:Module/etc/module.xsd”> <module name=“Vendor_Module”/> </config> |
How to register a Module?
Now, the last step is run the command which will enable and install the Vendor_Module module.
php bin/magento setup:upgrade
Module has been added and enabled in a Magento 2 application. You can check in app/etc/config.php file.
The value 1 means the module is enabled, and 0 that means the module is disabled. If Vendor_Module the module is set to 1, which means that the module has been successfully registered in a Magento 2.
2 responses to “What is Module in Magento 2”
I’ll bookmark your blog and test once more right here regularly.
I am relatively certain I’ll learn much new stuff proper right
here! Good luck with my best wishes!
Thank you so much for reading our blog.
Hope this blog is useful for you.
You can find another new blog, If you need any help then you can contact us.