create basic module magento2 - PowerPoint PPT Presentation

About This Presentation
Title:

create basic module magento2

Description:

create helloworld module magento2,create basic module magento2 – PowerPoint PPT presentation

Number of Views:69

less

Transcript and Presenter's Notes

Title: create basic module magento2


1
Create Hello World module In Magento2
2
Introduction Magento is an online ecommerce
platform thats used to develop modern, dynamic
web applications. Its 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 - modules name

app/code/Eglobe/Helloworld
5
Step 2 Create etc/module.xml file
  • Now, create etc folder and add the module.xml
    file
  • Contents would be

app/code/Eglobe/HelloWorld/etc/module.xml
lt?xml version"1.0"?gt ltconfig xmlnsxsi"http//w
ww.w3.org/2001/XMLSchema-instance"
xsinoNamespaceSchemaLocation"urnmagentoframewo
rkMo dule/etc/module.xsd"gt ltmodule
name"Eglobe_HelloWorld" setup_version"1.0.0"gt
lt/modulegt lt/configgt
6
Step 3 Create registration.php file
  • Create registration.php as follows
  • Code Contents

app/code/Eglobe/HelloWorld/registration.php
lt?php \Magento\Framework\Component\ ComponentReg
istrarregister(\Magento\Framework\ Component\Co
mponentRegistrarMODULE, 'Eglobe_HelloWorld', _
_DIR__)
7
Step 4 Create routes.xml file
  • Create routes.xml file

app/code/Eglobe/Helloworld/etc/frontend/
routes.xml 
  • Code Contents

lt?xml version"1.0"?gt ltconfig
xmlnsxsi"http//www.w3.org/2001/XMLSchema-instan
ce" xsinoNamespaceSchemaLocation"urnmagentofr
ameworkApp/etc/routes.xsd"gt ltrouter
id"standard"gt ltroute id"eglobe"
frontName"helloworld"gt ltmodule
name"Eglobe_HelloWorld" /gt lt/routegt
lt/routergt lt/configgt
After define the route, the URL path to our
module will be http//example.com/helloworld/
8
Step 5 Create controller file and action
  • Create controller file in the
  •  
  • Create Display.php

app/code/Eglobe/Helloworld/Controller/Index folder
app/code/Eglobe/HelloWorld/Index/Display.php
  • Content

lt?php namespace Eglobe\HelloWorld\Controller\Index
  class Display extends \Magento\Framework\App\Ac
tion\Action public function __construct(\Magent
o\Framework\App\Action\Context context)
return parent__construct(context)  
public function execute() echo 'Hello
World' exit
9
Step 6 Enable the module
Open your terminal and go to magento2 root. Run
the following command there
php bin/magento setupupgrade   sudo chmod -R
777 var pub/static generated
Now open the url http//example.com/helloworld/in
dex/display and you will see Hello World
Write a Comment
User Comments (0)
About PowerShow.com