How to do magento 2 module development?

 
Magento 2 module development, For any customzation in magento you need to create your own custom module. To change in magento’s core module is not recommended due to upgrade issue and code manangement issue.
 
In Today’s Topic I am going to explain how to do magento 2 module development from scratch.
 
If you are new to Magento 2, I would recommend to know about Magento first. You can check my previous post about Magento
 
 
Before Starting I hope you have installed magento2 in your system , If not and want to know how you can install magento2 in your ubuntu system   , Click here to Watch my video  In this video I have explained step by step that how u can install magento2 in your ubuntu system or alternatively you can check my post on how you can install magento 2 in ubuntu system.
 
 
So let’s start to create magento2 module.
 
 
First of all you need to create a folder under app/code Folder, You can create folder with any name like your company name or your name bcz this folder is a namespace for the folder.
 
app/code/MageAcademy
 
Here I have created folder with name MageAcademy. So MageAcademy is my namespace.
 
 
Now I will create registration.php file , This is for register my module.
<?php
 \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'MageAcademy_FirstModule', __DIR__ );

Now I will create etc folder and inside etc folder I will create module.xml to declare module
 
app/code/MageAcademy/FirstModule/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="MageAcademy_FirstModule" setup_version="1.0.0">         
    </module>
</config>

Now Run below command to enable module

php bin/magento module:enable NameSpace_ModuleName

If you have database related changes so you need to run below command.

php bin/magento setup:upgrade

Now Check if Your module is installed or not?
 
Now open app/etc/config.php and search for your module name MageAcademy_FirstModule
 
if there is MageAcademy_FirstModule=1 exist means your module is active now.


Happy Coding and keep visiting!

If You want to learn magento2 in depth. you can subscribe my channel by click.
 
https://youtube.com/phpacademy2020

Subscribe to our newsletter

Leave a Reply
Your email address will not be published. *