In this subject ,we are going to create a module in Magento 2. It’s following by 6 steps:
- Step 1: Create a module folder:
- Step 2: Declare the module by module.xml
- Step three: Register the module by registration.php
- Step 4: Install Setup, Allow or Disable the module
- Step 5: Create a route for the module.
- Step 6: Create controller and action.
Create a Module has some changes in Magento 2 .Create a Module in Magento 2 now have a bit different from Magento 1. And of course, you will need to learn about it.
Step1: Create a module folder:
We use module vendor Magestore and module name is HelloMagento. So we need create a brand new folder: app/code/Magestore/HelloMagento
Step 2: Declare the module by module.xml
- We want create a configuration in module etc directory. Magento 2 will use it to recognize the module’s identify and module’s version
- app/code/Magestore/HelloMagento/etc/module.xml
- Add this content to declare module title is HelloMangento and version 1.zero.zero
Step 3: Register the module by registration.php
- This file will probably be created in magento root folder:
- app/code/Magestore/HelloMagento/registration.php
- Add this content to registered the module:
Step 4: Set up Setup, Enable or Disable the module
After create all files of above steps. We can set up the module by way of command line. Please open your terminal and use these commands:
- Moreover, we are able to use some commands to view disabled module checklist, enable or disable a module:
- View disabled modules:
- php bin/magento module:status
- Enable module:
- PHP bin/magento module:enable Magestore_HelloMagento
- Disable module:
- PHP bin/magento module:disable Magestore_HelloMagento
- Note: In case you use xampp in ubuntu, please kind the correct directory for utilizing php command. Instance:
/opt/lampp/bin/php bin/magento module:disable Magestore_HelloMagento
SEE MORE : Magento Marketplace
Step 5: Create a route for the module.
- Each of magento 1 and magento 2 use this format url:
- http:// .com///
Example: http:// .com/customer/account/create
- http:// .com///
- So we'd like init router identify for the module before creating any controllers and actions sooner or later.
- Create a routers.xml file:
- app/code/Magestore/HelloMagento/and many others/frontend/routes.xml
- Add this content material:
Step 6: Create controller and motion.
- In the last step, we'll create url for displaying in browser: Hello Magento 2. We will change the world.
- Create an action file:
- app/code/Magestore/HelloMagento/Index/Index.php
- Add the content material:
These are all steps to create a brand new module in magento 2. Hope all you guys can study magento 2 easier with our sequence lesson. In next matter, we'll present you the way to create a view, block, template in magento 2.
The 6 steps I point out above is the shortest course of for you to Create a Module in Magento 2. With this information, you'll be able to handle the Module in Magento 2 easily. Every store has a Module in Magento 2 with many attributes.
Thanks for sharing this post, when i was having problem in creating controller, your guide helped me a lot, but for structure of module i followed this post, https://www.cloudways.com/blog/create-module-in-magento-2/
Nice article, but you forgot to mention one thing. After updating Magento 2, check if you are using cache storage other than Magento 2 filesystem (e.g. Varnish, Redis, Memcached, etc.), you will need to manually clear that cache too. (mentioned here: https://magenticians.com/update-magento-2-using-composer/ )
Thanks for the detailed explanation, Hng Quang. The elaboration of the steps with code makes the process much easier to understand.