Learn how to create basic module in Magento2. A step-by-step tutorial to learn create helloworld module in Magento2.Learn magento easily from eGlobe IT Solutions.
2. Introduction
Magento is an online ecommerce platform that’s used to develop modern, dynamic
web applications.
It’s an object-oriented PHP Framework .
This is the first article to print ‘Hello World’ in a series of articles in which we're
going to go on.
3. Contents
Step 1: Create a directory for the module Hello world.
Step 2: Create etc/module.xml file
Step 3: Create registration.php file
Step 4: Create routes.xml file
Step 5: Create controller file and action
Step 6: Enable the module
4. Step 1: Create a directory for the module
Hello World
Create a folder like below given format:
Here,
Eglobe - vender name
Helloworld - module’s name
app/code/Eglobe/Helloworld
7. Step 4: Create routes.xml file
• Create routes.xml file
app/code/Eglobe/Helloworld/etc/frontend/ routes.xml
• Code Contents:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/
routes.xsd">
<router id="standard">
<route id="eglobe" frontName="helloworld">
<module name="Eglobe_HelloWorld" />
</route>
</router>
</config>
After define the route, the URL path to our module will be: http://example.com/hellowo
8. Step 5: Create controller file and action
• Create controller file in the
• Create Display.php
app/code/Eglobe/HelloWorld/Index/Display.php
<?php
namespace EglobeHelloWorldControllerIndex;
class Display extends MagentoFrameworkAppActionAction
{ public function __construct(MagentoFrameworkAppActionContext
$context)
{ return parent::__construct($context);
}
public function execute() {
echo 'Hello World';
exit; }}
app/code/Eglobe/Helloworld/Controller/Index folder
• Content
9. Step 6: Enable the module
Open your terminal and go to magento2 root. Run the following command there:
php bin/magento setup:upgrade
sudo chmod -R 777 var pub/static generated
Now open the url http://example.com/helloworld/index/display and you will see He