SlideShare a Scribd company logo
How To Create A Simple Module in
Magento 2.0
A publication of
Mageno 2.0 was officially launched in 18th December 2014, which is a hot event to
Magento community.
To understand more about which will be changed compared with the previous version,
Magestore published a tutorial about creating a simple module in Magento 2.0.
1. Create a simple module in Magento 1.0
2. Magento 1.0 vs. Magento 2.0
3. Create a simple module in Magento 2.0
Firstly, I want to mention about way to create a simple module in Magento
1.0 so that you can make a comparison between this version with the
upcoming one: Magento 2.0
Create A Simple Module in
Magento 1.0
Declare your module in folder: app/etc/1
<?xml version=”1.0″?>
<config>
<modules>
<Magento_Hello>
<active>true</active>
<codePool>local</codePool>
</Magento_Hello>
</modules>
</config>
Module Configuration2
- Creat a controller : app/code/local/Magento/Hello/controllers/IndexController.php
class Magento_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
Module Configuration2
- Creat a block : app/code/local/Magento/Hello/Block/Hello.php
class Magento_Hello_Block_Hello extends Mage_Core_Block_Template
{
// write function here
}
Module Configuration2
-- Creat a configuration file config.xml : app/code/local/Magento/Hello/etc/config.xml
<?xml version=”1.0″?>
<config>
<modules>
<Magento_Hello>
<version>0.1.0</version>
</Magento_Hello>
</modules>
<global>
</global>
<frontend>
<routers>
<magento_hello>
<use>standard</use>
<args>
<module>Magento_Hello</module>
<frontName>hello</frontName>
</args>
</magento_hello>
</routers>
Module Configuration (continued)2
-- Creat a configuration file config.xml : app/code/local/Magento/Hello/etc/config.xml
<layout>
<updates>
<hello>
<file>hello.xml</file>
</hello>
</updates>
</layout>
</frontend>
<global>
<blocks>
<hello>
<class>Magento_Hello_Block</class>
</hello>
</blocks>
</global>
</config>
Create a frontend template3
- Write a file layout : app/design/frontend/default/default/layout/hello.xml
<layout version=”0.1.0″>
<hello_index_index>
<reference name=”root”>
<action method=”setTemplate”><template>page/1column.phtml</template></action>
</reference>
<reference name=”content”>
<block type=”hello/hello” name=”hello” template=”hello/hello.phtml”/>
</reference>
</hello_index_index>
</layout>
Create a frontend template3
- Push/Place content to file template hello.phtml
“This is a simple module in Magento 1.0”
When you access url http://localhost/magento20/hello/index/index, the browser will
display: “This is a simple module in Magento 1.0”
By looking at differences between Magento 1.0 & Magento 2.0, you can
easily visualize the folder structure in Magento 2.0. Thus, making a simple
module in Magento 2.0 is just a breeze. For deeper understand, move to
the next part & practice.
Magento 1.0 vs. Magento 2.0
Magento 1.0 Magento 2.0
Folder app/code includes subfolders: core,
community, local
Folder app/code includes
subfolders Magento and Zend. In Magento
1.0, Magento andZend are subfolders of the
folder core
Codes created by developers are located
at app/code/local or app/code/community
Codes created by developers are written directly
in app/code. There is no difference between local
and community
Module declaration file is a xml file
in app/etc/modules
Eg: Module Checkout in Magento Core is declared
in app/etc/modules/Mage_All.xml
Module declaration file is always module.xml which
is written directly to folder etc in the module
Eg: module Checkout in Magento Core is declared
in app/code/Magento/Checkout/etc/module.xml
Layout and template are saved in folder app/design
Eg: app/design/frontend/default/default/layout
Layout and template are saved in the folder “View”
in the module. The folder is the same level with
some folders like: Block, Controller, Helper, Model,
etc. in the module
Eg: app/code/Magento/Hello/view/frontend/layout
By looking at differences between Magento 1.0 & Magento 2.0, you can
easily visualize the folder structure in Magento 2.0. Thus, making a simple
module in Magento 2.0 is just a breeze. For deeper understand, move to
the next part & practice.
Create a simple module in
Magento 2.0
1
- Write the file module.xml in app/code/Magento/Hello/etc/module.xml to declare the module.
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/Module/
etc/module.xsd”>
<module name=”Magento_Hello” schema_version=”0.0.1″/>
</config>
2
- Create the file Index.php in app/code/Magento/Hello/Controller/Index/Index.php
Create controller and action
Folder Index plays the role of controller, while Index.php is action. The executive function
of action Index is execute()
2
- Create the file Index.php in app/code/Magento/Hello/Controller/Index/Index.php
Create controller and action
Folder Index plays the role of controller, while Index.php is action. The executive function
of action Index is execute()
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/Module/
etc/module.xsd”>
<module name=”Magento_Hello” schema_version=”0.0.1″/>
</config>
2 Create a block
app/code/Magento/Hello/Block/Hello.php
namespace MagentoHelloBlock;
class Hello extends MagentoFrameworkViewElementTemplate
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
}
2 - Write configuration file: /app/code/Magento/Hello/etc/frontend/routes.xml
- In Magento 1.0, every information about router, events of frontend and backend is
declared in Magento/Hello/etc/config.xml. However, in Magento 2.0, file config.xml only
configures the default configuration value in tag <default>
+) Information about router of frontend will be reported in:
Magento/Hello/etc/frontend/routes.xml (it is similar to backend)
+) Event of frontend will be declared in: Magento/Hello/ect/frontend/events.xml (it is
similar to backend)
In the scope of a simple module, we only declare routers in
Magento/Hello/etc/frontend/routes.xml
2 - Write configuration file: /app/code/Magento/Hello/etc/frontend/routes.xml
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=”../../../../../../lib/internal/Magento/Framework/App/et
c/routes.xsd”>
<router id=”standard”>
<route id=”hello” frontName=”hello”>
<module name=”Magento_Hello” />
</route>
</router>
</config>
3 - Create a frontend template
- Write a layout file: appcodeMagentoHelloviewfrontendlayouthello_index_index.xml
Name of layout file is really important in this step. It will be named after the structure:
router name_controlle namer_action name
<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=”../../../../../../../lib/internal/Magento/Framework/View
/Layout/etc/page_configuration.xsd”>
<body>
<referenceContainer name=”content”>
<block class=”MagentoHelloBlockHello” name=”hello”
template=”success.phtml”>
</block>
</referenceContainer>
</body>
</page>
3 - Create a frontend template
3 Then, we create a file success.phtml as reporting in layout file:
appcodeMagentoHelloviewfrontendtemplatessuccess.phtml
<?php echo „Successful! This is a simple module in Magento 2.0′; ?>
4 Activate Magento_Hello extension in configuration file
- Open the file app/etc/config.xml
- In the array ‘module’, add the element: ‘Magento_Hello’ => 1,
You have known all the steps to write a simple module in Magento 2.0. When you run the link:
http://localhost/magento20/hello/index/index the result will be shown as the following:
- To download full pdf version,
visit our blog post here
- To never miss any updates or
tutorial about Magento 2.0,
subscribe to our blog right
now.
… AND
YOU’RE
DONE!

More Related Content

Similar to How to-create-a-simple-module-in-magento-2.0

Federico Soich - Upgrading Magento Version
Federico Soich - Upgrading Magento VersionFederico Soich - Upgrading Magento Version
Federico Soich - Upgrading Magento Version
Meet Magento Italy
 
How to create a simple module in Magento 2.0
How to create a simple module in Magento 2.0How to create a simple module in Magento 2.0
How to create a simple module in Magento 2.0
MageWorld
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
Mage Guru
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
Ravi Mehrotra
 
Mangento
MangentoMangento
Mangento
Ravi Mehrotra
 
12 Amazing Features of Magento 2
12 Amazing Features of Magento 212 Amazing Features of Magento 2
12 Amazing Features of Magento 2
Schogini Systems Pvt Ltd
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
Trọng Huỳnh
 
Magento++
Magento++Magento++
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Joke Puts
 
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
Mathew Beane
 
Make implementation of third party elements in magento 2 in 5-times easier
Make implementation of third party elements in magento 2 in 5-times easierMake implementation of third party elements in magento 2 in 5-times easier
Make implementation of third party elements in magento 2 in 5-times easier
Elena Kulbich
 
Architecture and Analytical Study of Magento
Architecture and Analytical Study of MagentoArchitecture and Analytical Study of Magento
Architecture and Analytical Study of Magento
IRJET Journal
 
Magento 2 integration tests
Magento 2 integration testsMagento 2 integration tests
Magento 2 integration tests
Dusan Lukic
 
Maven plugin guide using Modello Framework
Maven plugin guide using Modello FrameworkMaven plugin guide using Modello Framework
Maven plugin guide using Modello Framework
fulvio russo
 
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
Magestore
 
Develop magento 2 custom shipping module
Develop magento 2 custom shipping moduleDevelop magento 2 custom shipping module
Develop magento 2 custom shipping module
The Brihaspati Infotech Pvt. Ltd.
 
Magento 2 Event Manager Extension
Magento 2 Event Manager ExtensionMagento 2 Event Manager Extension
Magento 2 Event Manager Extension
MageAnts
 
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
eGlobe IT Solutions Pvt Ltd
 
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
eGlobe IT Solutions
 
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULESBEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
Kuldeep Sharma
 

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
 
How to create a simple module in Magento 2.0
How to create a simple module in Magento 2.0How to create a simple module in Magento 2.0
How to create a simple module in Magento 2.0
 
Mageguru - magento custom module development
Mageguru -  magento custom module development Mageguru -  magento custom module development
Mageguru - magento custom module development
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Mangento
MangentoMangento
Mangento
 
12 Amazing Features of Magento 2
12 Amazing Features of Magento 212 Amazing Features of Magento 2
12 Amazing Features of Magento 2
 
M2ModuleDevelopmenteBook
M2ModuleDevelopmenteBookM2ModuleDevelopmenteBook
M2ModuleDevelopmenteBook
 
Magento++
Magento++Magento++
Magento++
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
 
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
 
Make implementation of third party elements in magento 2 in 5-times easier
Make implementation of third party elements in magento 2 in 5-times easierMake implementation of third party elements in magento 2 in 5-times easier
Make implementation of third party elements in magento 2 in 5-times easier
 
Architecture and Analytical Study of Magento
Architecture and Analytical Study of MagentoArchitecture and Analytical Study of Magento
Architecture and Analytical Study of Magento
 
Magento 2 integration tests
Magento 2 integration testsMagento 2 integration tests
Magento 2 integration tests
 
Maven plugin guide using Modello Framework
Maven plugin guide using Modello FrameworkMaven plugin guide using Modello Framework
Maven plugin guide using Modello Framework
 
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
 
Develop magento 2 custom shipping module
Develop magento 2 custom shipping moduleDevelop magento 2 custom shipping module
Develop magento 2 custom shipping module
 
Magento 2 Event Manager Extension
Magento 2 Event Manager ExtensionMagento 2 Event Manager Extension
Magento 2 Event Manager Extension
 
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
 
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
 
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULESBEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
BEGINNERS’ GUIDE TO MAGENTO PLUGINS, EXTENSIONS, MODULES
 

More from Daniele Crupi

Magento Design Guide
Magento Design GuideMagento Design Guide
Magento Design Guide
Daniele Crupi
 
Importanza Del Letto
Importanza Del LettoImportanza Del Letto
Importanza Del LettoDaniele Crupi
 
Labirratifadiventaredonna
LabirratifadiventaredonnaLabirratifadiventaredonna
LabirratifadiventaredonnaDaniele Crupi
 
Americans
AmericansAmericans
Americans
Daniele Crupi
 
11 Motivi Per Non Bere Con Gli Amici
11 Motivi Per Non Bere Con Gli Amici11 Motivi Per Non Bere Con Gli Amici
11 Motivi Per Non Bere Con Gli AmiciDaniele Crupi
 

More from Daniele Crupi (13)

Magento Design Guide
Magento Design GuideMagento Design Guide
Magento Design Guide
 
Importanza Del Letto
Importanza Del LettoImportanza Del Letto
Importanza Del Letto
 
Fotofantastiche
FotofantasticheFotofantastiche
Fotofantastiche
 
Il Lavoro
Il LavoroIl Lavoro
Il Lavoro
 
Labirratifadiventaredonna
LabirratifadiventaredonnaLabirratifadiventaredonna
Labirratifadiventaredonna
 
Lego
LegoLego
Lego
 
Massime
MassimeMassime
Massime
 
Oroscopo Veneto
Oroscopo VenetoOroscopo Veneto
Oroscopo Veneto
 
Peluquero
PeluqueroPeluquero
Peluquero
 
Americans
AmericansAmericans
Americans
 
11 Motivi Per Non Bere Con Gli Amici
11 Motivi Per Non Bere Con Gli Amici11 Motivi Per Non Bere Con Gli Amici
11 Motivi Per Non Bere Con Gli Amici
 
Visita Medica
Visita MedicaVisita Medica
Visita Medica
 
Polo Norde Sud
Polo Norde SudPolo Norde Sud
Polo Norde Sud
 

Recently uploaded

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 

Recently uploaded (20)

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 

How to-create-a-simple-module-in-magento-2.0

  • 1. How To Create A Simple Module in Magento 2.0 A publication of
  • 2. Mageno 2.0 was officially launched in 18th December 2014, which is a hot event to Magento community. To understand more about which will be changed compared with the previous version, Magestore published a tutorial about creating a simple module in Magento 2.0. 1. Create a simple module in Magento 1.0 2. Magento 1.0 vs. Magento 2.0 3. Create a simple module in Magento 2.0
  • 3. Firstly, I want to mention about way to create a simple module in Magento 1.0 so that you can make a comparison between this version with the upcoming one: Magento 2.0 Create A Simple Module in Magento 1.0
  • 4. Declare your module in folder: app/etc/1 <?xml version=”1.0″?> <config> <modules> <Magento_Hello> <active>true</active> <codePool>local</codePool> </Magento_Hello> </modules> </config>
  • 5. Module Configuration2 - Creat a controller : app/code/local/Magento/Hello/controllers/IndexController.php class Magento_Hello_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(); $this->renderLayout(); } }
  • 6. Module Configuration2 - Creat a block : app/code/local/Magento/Hello/Block/Hello.php class Magento_Hello_Block_Hello extends Mage_Core_Block_Template { // write function here }
  • 7. Module Configuration2 -- Creat a configuration file config.xml : app/code/local/Magento/Hello/etc/config.xml <?xml version=”1.0″?> <config> <modules> <Magento_Hello> <version>0.1.0</version> </Magento_Hello> </modules> <global> </global> <frontend> <routers> <magento_hello> <use>standard</use> <args> <module>Magento_Hello</module> <frontName>hello</frontName> </args> </magento_hello> </routers>
  • 8. Module Configuration (continued)2 -- Creat a configuration file config.xml : app/code/local/Magento/Hello/etc/config.xml <layout> <updates> <hello> <file>hello.xml</file> </hello> </updates> </layout> </frontend> <global> <blocks> <hello> <class>Magento_Hello_Block</class> </hello> </blocks> </global> </config>
  • 9. Create a frontend template3 - Write a file layout : app/design/frontend/default/default/layout/hello.xml <layout version=”0.1.0″> <hello_index_index> <reference name=”root”> <action method=”setTemplate”><template>page/1column.phtml</template></action> </reference> <reference name=”content”> <block type=”hello/hello” name=”hello” template=”hello/hello.phtml”/> </reference> </hello_index_index> </layout>
  • 10. Create a frontend template3 - Push/Place content to file template hello.phtml “This is a simple module in Magento 1.0” When you access url http://localhost/magento20/hello/index/index, the browser will display: “This is a simple module in Magento 1.0”
  • 11. By looking at differences between Magento 1.0 & Magento 2.0, you can easily visualize the folder structure in Magento 2.0. Thus, making a simple module in Magento 2.0 is just a breeze. For deeper understand, move to the next part & practice. Magento 1.0 vs. Magento 2.0
  • 12. Magento 1.0 Magento 2.0 Folder app/code includes subfolders: core, community, local Folder app/code includes subfolders Magento and Zend. In Magento 1.0, Magento andZend are subfolders of the folder core Codes created by developers are located at app/code/local or app/code/community Codes created by developers are written directly in app/code. There is no difference between local and community Module declaration file is a xml file in app/etc/modules Eg: Module Checkout in Magento Core is declared in app/etc/modules/Mage_All.xml Module declaration file is always module.xml which is written directly to folder etc in the module Eg: module Checkout in Magento Core is declared in app/code/Magento/Checkout/etc/module.xml Layout and template are saved in folder app/design Eg: app/design/frontend/default/default/layout Layout and template are saved in the folder “View” in the module. The folder is the same level with some folders like: Block, Controller, Helper, Model, etc. in the module Eg: app/code/Magento/Hello/view/frontend/layout
  • 13. By looking at differences between Magento 1.0 & Magento 2.0, you can easily visualize the folder structure in Magento 2.0. Thus, making a simple module in Magento 2.0 is just a breeze. For deeper understand, move to the next part & practice. Create a simple module in Magento 2.0
  • 14. 1 - Write the file module.xml in app/code/Magento/Hello/etc/module.xml to declare the module. <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/Module/ etc/module.xsd”> <module name=”Magento_Hello” schema_version=”0.0.1″/> </config>
  • 15. 2 - Create the file Index.php in app/code/Magento/Hello/Controller/Index/Index.php Create controller and action Folder Index plays the role of controller, while Index.php is action. The executive function of action Index is execute()
  • 16. 2 - Create the file Index.php in app/code/Magento/Hello/Controller/Index/Index.php Create controller and action Folder Index plays the role of controller, while Index.php is action. The executive function of action Index is execute() <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/Module/ etc/module.xsd”> <module name=”Magento_Hello” schema_version=”0.0.1″/> </config>
  • 17. 2 Create a block app/code/Magento/Hello/Block/Hello.php namespace MagentoHelloBlock; class Hello extends MagentoFrameworkViewElementTemplate { public function _prepareLayout() { return parent::_prepareLayout(); } }
  • 18. 2 - Write configuration file: /app/code/Magento/Hello/etc/frontend/routes.xml - In Magento 1.0, every information about router, events of frontend and backend is declared in Magento/Hello/etc/config.xml. However, in Magento 2.0, file config.xml only configures the default configuration value in tag <default> +) Information about router of frontend will be reported in: Magento/Hello/etc/frontend/routes.xml (it is similar to backend) +) Event of frontend will be declared in: Magento/Hello/ect/frontend/events.xml (it is similar to backend) In the scope of a simple module, we only declare routers in Magento/Hello/etc/frontend/routes.xml
  • 19. 2 - Write configuration file: /app/code/Magento/Hello/etc/frontend/routes.xml <config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../../../../../lib/internal/Magento/Framework/App/et c/routes.xsd”> <router id=”standard”> <route id=”hello” frontName=”hello”> <module name=”Magento_Hello” /> </route> </router> </config>
  • 20. 3 - Create a frontend template - Write a layout file: appcodeMagentoHelloviewfrontendlayouthello_index_index.xml Name of layout file is really important in this step. It will be named after the structure: router name_controlle namer_action name <page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../../../../../../lib/internal/Magento/Framework/View /Layout/etc/page_configuration.xsd”> <body> <referenceContainer name=”content”> <block class=”MagentoHelloBlockHello” name=”hello” template=”success.phtml”> </block> </referenceContainer> </body> </page>
  • 21. 3 - Create a frontend template
  • 22. 3 Then, we create a file success.phtml as reporting in layout file: appcodeMagentoHelloviewfrontendtemplatessuccess.phtml <?php echo „Successful! This is a simple module in Magento 2.0′; ?>
  • 23. 4 Activate Magento_Hello extension in configuration file - Open the file app/etc/config.xml - In the array ‘module’, add the element: ‘Magento_Hello’ => 1,
  • 24. You have known all the steps to write a simple module in Magento 2.0. When you run the link: http://localhost/magento20/hello/index/index the result will be shown as the following:
  • 25. - To download full pdf version, visit our blog post here - To never miss any updates or tutorial about Magento 2.0, subscribe to our blog right now. … AND YOU’RE DONE!