How to create an extension or module in magento 2 - Magesan

How to create an extension or module in magento 2

How to create an extension or module in magento 2

Magento2 custom module creation allow to add new feature to your magento store. It will open all the resources for you to adding rich features to your ecommerce store beyond limits.

For creating Extension in magento2 we need to create 2 mandatory files for recognizing magento2 as our extension.
1) registration.php
2) etc/module.xml

Let’s give our extension a name which magento2 can recongnize and do the stuff for it.

Magesan_Extension

Where Magesan is our package name and Extension is our module or extension name and they all are must unique.

1) registration.php file will register our extension

Path :- app/code/Magesan/Extension/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Magesan_Extension',
    __DIR__
)

2) module.xml file will allows us to create and manage the magento2 schema version and on which the module is depend on.

Path :- app/code/Magesan/Extension/etc/module.xml

<?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="Magesan_Extension" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Catalog" />
            <module name="Magento_Backend" />
            <module name="Magento_Customer" />
        </sequence>
    </module>
</config>

Our extension/module is ready to use now. You can check if your module listed in the magento2 by performing a command
php bin/magento module:status
modulestatus

Enable the module by performing :- php bin/magento module:enable Magesan_Extension
enabledmodule

You must have to perform the setup:upgrade command after enabling a module
php bin/magento setup:upgrade

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>