You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Magento 2 Module development orMagento 2 Hello World Simple Module trends is increase rapidly while Magento release official version. That why we -Mageplaza - are wring about a topic that introduces how to create a simpleHello World module in Magento 2.As you know, the module is a directory that containsblocks, controllers, models, helper, etc - that are related to a specific business feature. In Magento 2, modules will be live inapp/code directory of a Magento installation, with this format:app/code/<Vendor>/<ModuleName>. Now we will follow this steps to create a simple module which work on Magento 2 and displayHello World.
Magento 2 Hello World module by Mageplaza.com
Step 1: Create a directory for the module like above format.
Step 2: Declare module by using configuration file module.xml
Step 3: Register module by registration.php
Step 4: Enable the module
Step 5: Create a Routers for the module.
Step 6: Create controller and action.
Step 1. Create a directory for the module like above format.
In this module, we will useMageplaza for Vendor name andHelloWorld for ModuleName. So we need to make this folder:app/code/Mageplaza/HelloWorld
Step 2. Declare module by using configuration file module.xml
Magento 2 looks for configuration information for each module in that module’s etc directory. We need to create folder etc and add module.xml:
In this file, we register a module with nameMageplaza_HelloWorld and the version is1.0.0.
Step 3. Register module by registration.php
All Magento 2 module must be registered in the Magento system through the magento ComponentRegistrar class. This file will be placed in module root directory.In this step, we need to create this file:
By finish above step, you have created an empty module. Now we will enable it in Magento environment.Before enable the module, we must check to make sure Magento has recognize our module or not by enter the following at the command line:
php bin/magento module:status
If you follow above step, you will see this in the result:
List of disabled modules:Mageplaza_HelloWorld
This means the module has recognized by the system but it is still disabled. Run this command to enable it:
The Router is used to assign a URL to a corresponding controller and action. In this module, we need to create a route for frontend area. So we need to add this file:
After define the route, the URL path to our module will be:http://example.com/helloworld/*
Step 6. Create controller and action.
In this step, we will create controller and action to displayHello World.Now we will choose the url for this action. Let assume that the url will be:http://example.com/helloworld/index/display