Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Create Basic module in magento2| Tuitorial hello world Magento2

24 views

Published on

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.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Create Basic module in magento2| Tuitorial hello world Magento2

  1. 1. Create Hello World module In Magento2
  2. 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. 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. 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
  5. 5. Step 2: Create etc/module.xml file  Now, create etc folder and add the module.xml file  Contents would be: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Mo dule/ etc/module.xsd"> <module name="Eglobe_HelloWorld" setup_version="1.0.0"> </module> </config> app/code/Eglobe/HelloWorld/etc/module.xml
  6. 6. Step 3: Create registration.php file  Create registration.php as follows:  Code Contents: app/code/Eglobe/HelloWorld/registration.php <?php MagentoFrameworkComponent ComponentRegistrar::register(MagentoFramework ComponentComponentRegistrar::MODULE, 'Eglobe_HelloWorld', __DIR__);
  7. 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. 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. 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

×