Magewallet

Magento 2 Extensions, Themes & Services

How to create a Magento 2 extension

Happy to see you guys again!

In this blog post, we will learn how to create Magento 2 extension step by step and basic knowledge required to setup a module. we will also introduce the coding of Magento 2 in the form of a “Hello Developer” style. This blog post also includes some basic functionality, covering as many development aspects as possible in this case.

Lets consider module with Namespace is Magewallet and Module Name is HelloDeveloper. Lets list down all the files require for this extension.

1)app/code/Magewallet/HelloDeveloper/registration.php
2)app/code/Magewallet/HelloDeveloper/composer.json
3)app/code/Magewallet/HelloDeveloper/etc/module.xml
4)app/code/Magewallet/HelloDeveloper/etc/frontend/routes.xml
5)app/code/Magewallet/HelloDeveloper/Controller/Index/index.php
6)app/code/Magewallet/Helloworld/View/frontend/layout/hellodeveloper_index_index.xml
7)app/code/Magewallet/HelloDeveloper/Block/HelloDeveloper.php
8)app/code/Magewallet/HelloDeveloper/View/frontend/templates/hellodeveloper.phtml

First we will create registration file at app/code/Magewallet/HelloDeveloper/registration.php file

Now, create a composer.json file in app/code/Magewallet/HelloDeveloper/ folder as per below.

now create module.xml file in app/code/Magewallet/HelloDeveloper/etc

Create a frontend router in app/code/Magewallet/HelloDeveloper/etc/frontend/routes.xml

here the router ID shown which router we will use either frontend or adminhtml. Pay attention that the front name is the first part of the URL and it should be unique.

Create a Controller action

Create the file index.php in app/code/Magewallet/HelloDeveloper/Controller/Index.

Create a layout file at app\code\Magewallet\Helloworld\View\frontend\layout\hellodeveloper_index_index.xml

Create block file app/code/Magewallet/HelloDeveloper/Block/HelloDeveloper.php

Create a template file app/code/Magewallet/HelloDeveloper/View/frontend/templates/hellodeveloper.phtml

Active Magewallet_HelloDeveloper extension

Open Command line in folder root of Magento and run commands

In order to cross check the routing and controller access below URL.
http://localhost/magento2/hellodeveloper/index/index

You have known all the steps to write a simple extension in Magento 2. if you have any questions about this steps of Magento 2 extension development, please ask them in comments.
Enjoy Magento 2! Enjoy Magewallet!!

Mahendra Paladiya
Mahendra is a Web Developer whose passions includes web development, technical blog writing, and database management. His passion for web development pushed him into learning how to handle different platforms like Core PHP, Magento, Prestashop, WordPress, CodeIgniter, CakePHP and Oracle.

1 Comment

  1. Herder Sutkus

    May 3, 2016 at 8:38 am

    Very nice post. can you please add zip file with the above code snippet? I really appreciate for your efforts!! Thanks Mahendra.

Leave a Reply

Your email address will not be published.

*

 

© 2017 Magewallet

Theme by Anders NorenUp ↑