What is Module in Magento 2

 In Magento blog

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.

<strong>Module are two locations where a module can be located in Magento 2</strong>

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.

<?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.

<?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.

Leave a Comment

0