SlideShare a Scribd company logo
1 of 14
How to create a module in Magento 2.0
(Updated in August 2015)
2
1 THE STRUCTURE OF A SIMPLE MODULE
Magento 1 vs Magento 2
Some new folders in Magento 2
2
CREATE A SIMPLE MODULE IN MAGENTO 2
Step 1: Create configuration files
Step 2: Create controller, layout and template files
Step 3: Activate the module in the configuration file
OUTLINE
MAGENTO 2
Folders and files of a module are put in
only a package and located in app/code
folder
1. THE STRUCTURE OF A SIMPLE MODULE
MAGENTO 1
Folders and files of a module are located
in different folders: app/code/local,
app/code/community, app/design,
app/etc, app/locale, js, skin,…
Some new folders in Magento 2
i18n: store the .csv files for module
translator. Eg: en_US.csv, de_DE.csv
Setup: store the files which are used to
create tables or insert data to the
database.
View: This folder stores the layout,
template, image, CSS and Javascript
files which are used for your module.
Let’s create folders with the structure as
following:
Namespace: Tutorial
Module name: Example
Example link on Local host:
http://localhost/magento2/exam
ple/index/index/
2. CREATE A SIMPLE MODULE IN MAGENTO 2
Step 1: Create configuration files
1.1. Create file: app/code/Tutorial/Example/etc/module.xml
Purpose: Declare your module
Source Code:
(Go to our blog tutorial for full source code)
Step 1: Create configuration files
1.2 Create file:
app/code/Tutorial/Example/etc/frontend/routes.xml
Purpose: Declare the router of module for frontend
(Go to our blog tutorial for full source code)
Step 2: Create controller, layout and template files
2.1 Create the controller
file: app/code/Tutorial/Example/Controller/Index/Index.php
=> The souce code is found in our blog tutorial
Step 2: Create controller, layout and template files
2.2 Create the layout file:
app/code/Tutorial/Example/view/frontend/layout/example_inde
x_index.xml
(Go to our blog tutorial for full source code)
Step 2: Create controller, layout and template files
2.3 Create the template file:
app/code/Tutorial/Example/view/frontend/templates/index.phtml
(Go to our blog tutorial for full source code)
Step 3: Activate the module in the configuration file
3.1 Activate module by opening app/etc/config.php file then
add this line “'Tutorial_Example' => 1” into it:
(Go to our blog tutorial for full source code)
Step 3: Activate the module in the configuration file
3.2 Open the Command in Windows (or the Terminal in Linux
and MAC OS). Go to Magento root folder and run this
command line to install module:
binmagento setup:upgrade
(Go to our blog tutorial for full source code)
Step 3: Activate the module in the configuration file
3.3 Clear the Magento cache then access with
url http://localhost/magento2/example/index/index/
Following MageWorld Magento 2 Tutorial Series…

More Related Content

Viewers also liked

Comm final project
Comm final projectComm final project
Comm final project
davidtrotto
 
Fundusze inwestycyjne
Fundusze inwestycyjneFundusze inwestycyjne
Fundusze inwestycyjne
Gucio Silva
 
Models by Percent Discount
Models by Percent DiscountModels by Percent Discount
Models by Percent Discount
TrueCar
 
Blog her devries_surveyfinal, ec
Blog her devries_surveyfinal, ecBlog her devries_surveyfinal, ec
Blog her devries_surveyfinal, ec
Elisa Camahort Page
 

Viewers also liked (18)

Presentatie taskforce social op Interact 2010 deel1
Presentatie taskforce social op Interact 2010 deel1Presentatie taskforce social op Interact 2010 deel1
Presentatie taskforce social op Interact 2010 deel1
 
Comm final project
Comm final projectComm final project
Comm final project
 
Faq
FaqFaq
Faq
 
Svadebnaya masterskaya
Svadebnaya masterskayaSvadebnaya masterskaya
Svadebnaya masterskaya
 
Png还是jpg,这是个问题
Png还是jpg,这是个问题Png还是jpg,这是个问题
Png还是jpg,这是个问题
 
Fundusze inwestycyjne
Fundusze inwestycyjneFundusze inwestycyjne
Fundusze inwestycyjne
 
Presentation1
Presentation1Presentation1
Presentation1
 
237-Vineyards-comptine
237-Vineyards-comptine237-Vineyards-comptine
237-Vineyards-comptine
 
Models by Percent Discount
Models by Percent DiscountModels by Percent Discount
Models by Percent Discount
 
2011 Toyota Corolla Plano
2011 Toyota Corolla Plano2011 Toyota Corolla Plano
2011 Toyota Corolla Plano
 
2011 Toyota Highlnder Plano
2011 Toyota Highlnder Plano2011 Toyota Highlnder Plano
2011 Toyota Highlnder Plano
 
Peter Crosby - Levelling the Playing Field: Social Recruitment & Professional...
Peter Crosby - Levelling the Playing Field: Social Recruitment & Professional...Peter Crosby - Levelling the Playing Field: Social Recruitment & Professional...
Peter Crosby - Levelling the Playing Field: Social Recruitment & Professional...
 
Social Media: Which to? How to? Why to?
Social Media: Which to? How to? Why to?Social Media: Which to? How to? Why to?
Social Media: Which to? How to? Why to?
 
Awesome images
Awesome imagesAwesome images
Awesome images
 
Blog her devries_surveyfinal, ec
Blog her devries_surveyfinal, ecBlog her devries_surveyfinal, ec
Blog her devries_surveyfinal, ec
 
Central Banks Macro Adjustments
Central Banks Macro AdjustmentsCentral Banks Macro Adjustments
Central Banks Macro Adjustments
 
Communique -- May 2010
Communique -- May 2010Communique -- May 2010
Communique -- May 2010
 
Rrb po-clerk-capsule-2015
Rrb po-clerk-capsule-2015Rrb po-clerk-capsule-2015
Rrb po-clerk-capsule-2015
 

Similar to How to create a simple module in Magento 2.0

M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
Trọng Huỳnh
 

Similar to How to create a simple module in Magento 2.0 (20)

Federico Soich - Upgrading Magento Version
Federico Soich - Upgrading Magento VersionFederico Soich - Upgrading Magento Version
Federico Soich - Upgrading Magento Version
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
 
How To Create Theme in Magento 2 - Part 1
How To Create Theme in Magento 2 - Part 1How To Create Theme in Magento 2 - Part 1
How To Create Theme in Magento 2 - Part 1
 
How to create theme in Magento 2 - Part 2
How to create theme in Magento 2 - Part 2How to create theme in Magento 2 - Part 2
How to create theme in Magento 2 - Part 2
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2
 
12 Amazing Features of Magento 2
12 Amazing Features of Magento 212 Amazing Features of Magento 2
12 Amazing Features of Magento 2
 
Struts2 tutorial
Struts2 tutorialStruts2 tutorial
Struts2 tutorial
 
Struts2 tutorial
Struts2 tutorialStruts2 tutorial
Struts2 tutorial
 
Struts2 tutorial
Struts2 tutorialStruts2 tutorial
Struts2 tutorial
 
Create Basic module in magento2| Tuitorial hello world Magento2
Create Basic module in magento2| Tuitorial hello world Magento2Create Basic module in magento2| Tuitorial hello world Magento2
Create Basic module in magento2| Tuitorial hello world Magento2
 
Create basic hello world module in magento2
Create basic hello world module in magento2Create basic hello world module in magento2
Create basic hello world module in magento2
 
Architecture and Analytical Study of Magento
Architecture and Analytical Study of MagentoArchitecture and Analytical Study of Magento
Architecture and Analytical Study of Magento
 
Convert Magento 1 Extensions to Magento 2
Convert Magento 1 Extensions to Magento 2Convert Magento 1 Extensions to Magento 2
Convert Magento 1 Extensions to Magento 2
 
fuelOrigin.docx
fuelOrigin.docxfuelOrigin.docx
fuelOrigin.docx
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Mangento
MangentoMangento
Mangento
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2
 

Recently uploaded

Recently uploaded (20)

WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 

How to create a simple module in Magento 2.0

  • 1. How to create a module in Magento 2.0 (Updated in August 2015) 2
  • 2. 1 THE STRUCTURE OF A SIMPLE MODULE Magento 1 vs Magento 2 Some new folders in Magento 2 2 CREATE A SIMPLE MODULE IN MAGENTO 2 Step 1: Create configuration files Step 2: Create controller, layout and template files Step 3: Activate the module in the configuration file OUTLINE
  • 3. MAGENTO 2 Folders and files of a module are put in only a package and located in app/code folder 1. THE STRUCTURE OF A SIMPLE MODULE MAGENTO 1 Folders and files of a module are located in different folders: app/code/local, app/code/community, app/design, app/etc, app/locale, js, skin,…
  • 4. Some new folders in Magento 2 i18n: store the .csv files for module translator. Eg: en_US.csv, de_DE.csv Setup: store the files which are used to create tables or insert data to the database. View: This folder stores the layout, template, image, CSS and Javascript files which are used for your module.
  • 5. Let’s create folders with the structure as following: Namespace: Tutorial Module name: Example Example link on Local host: http://localhost/magento2/exam ple/index/index/ 2. CREATE A SIMPLE MODULE IN MAGENTO 2
  • 6. Step 1: Create configuration files 1.1. Create file: app/code/Tutorial/Example/etc/module.xml Purpose: Declare your module Source Code: (Go to our blog tutorial for full source code)
  • 7. Step 1: Create configuration files 1.2 Create file: app/code/Tutorial/Example/etc/frontend/routes.xml Purpose: Declare the router of module for frontend (Go to our blog tutorial for full source code)
  • 8. Step 2: Create controller, layout and template files 2.1 Create the controller file: app/code/Tutorial/Example/Controller/Index/Index.php => The souce code is found in our blog tutorial
  • 9. Step 2: Create controller, layout and template files 2.2 Create the layout file: app/code/Tutorial/Example/view/frontend/layout/example_inde x_index.xml (Go to our blog tutorial for full source code)
  • 10. Step 2: Create controller, layout and template files 2.3 Create the template file: app/code/Tutorial/Example/view/frontend/templates/index.phtml (Go to our blog tutorial for full source code)
  • 11. Step 3: Activate the module in the configuration file 3.1 Activate module by opening app/etc/config.php file then add this line “'Tutorial_Example' => 1” into it: (Go to our blog tutorial for full source code)
  • 12. Step 3: Activate the module in the configuration file 3.2 Open the Command in Windows (or the Terminal in Linux and MAC OS). Go to Magento root folder and run this command line to install module: binmagento setup:upgrade (Go to our blog tutorial for full source code)
  • 13. Step 3: Activate the module in the configuration file 3.3 Clear the Magento cache then access with url http://localhost/magento2/example/index/index/
  • 14. Following MageWorld Magento 2 Tutorial Series…