So if you are creating the very first module in Magento, you have come to the right place because this blog will guide you on how to create the basic module with the proper file structure. To get that right please follow the module creation procedure with the commands given below.
To start with creating module go to app/code folder. Here is where we begin with module creation.
Let us create a basic “Welcome” module.
Module Folder Creation:
Make sure you are in the app/code folder. In that you have to create a vendor folder and in vendor folder, you have to create your module folder.
In the code folder create two new folders like app/code/Vendor_Name/Module_Name. When you are using this module in the program you have to mention the module as “VendorName_ModuleName”
For example “Coditron_Welcome”. Here Coditron is our vendor_name and Welcome is our module_name.
So we have created the module and its path is app/code/Coditron/Welcome. Let’s have a look at the module file structure so that you can get a clear idea.
Create folders and files as shown below in the file structure. The file structure of your module should be as given below:
After this, you have to create a registration.php file. This file is very important because in this file your module is registered.
Now create module.xml file in app/code/Coditron/Welcome/etc folder.
1) To check module status:
2) You will get a module list, in that disable modules list our module name is present so, let us enable our module by the below command:
Your module is enabled. And you can check whether your module is enabled or not by viewing if the value of your module name is set to “1”.
Open app/etc/config.php file and check the value.
‘Coditron_Welcome’ => 1,
Now run the below commands to upgrade and deploy your Magento.
After these commands create the routes.xml file in the app/code/Coditron/Welcome/etc/frontend/ folder.
Create a file Index.php in the app/code/Coditron/Welcome/Controller/Index/ folder.
Now Your Module is Ready.
So that is the first module in Magento2. I hope you enjoyed this blog. Isn’t it exciting? If you want to learn about different modules you can follow my other blogs.