The beta version of Magento 2 was released several months ago and after that there are some updates on this beta version as well. With developers, Magento 2.0 is quite challenging because resources to learn are very limited.
Understand such difficulties, MageWorld are happy to introduce you a tutorial series on Magento 2.0. We hope you will enjoy them and make use of it easily!
Let’s get started with the first post: “How to create a simple module in Magento 2.0”
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/