Day 1: Magento 2 Module Creation for Beginners

Welcome to Day 1 of Magento Advent Calendar. I will share practices that would help you improve your knowledge when working with Magento 2 projects.

Let’s start from the module structure.

A skeleton Magento 2 module typically includes 2 required files: registartion.php and module.xml. The file is responsible to registering a module in Magento 2.

The registration.php file:

<?php

declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'MageMastery_Module',
     __DIR__
);

The module.xml file provides information about module name and any configuration dependencies.

The etc/module.xml file:

<?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="MageMastery_Module" />
</config>

Once both files are created, the module can be registered and enabled in a Magento 2 application. In this case we create the foundation of a future functionality.

I also created a video for Day 1 of the Magento Advent Calendar that covers optional composer.json file for the module. Make sure to watch it.

Similar Posts

Leave a Reply