Magento 2.0 has been the talk for some time now. Developers are working through its functionalities, and creating example versions to understand the framework. Here you will learn how to create a simple module using this platform.
Declare the Module
The module that you are creating is Magento_Hello, an example simple module. Before you do anything, you will need to declare the module. Begin by writing the file module.xml in the path app/code/magento/hello/etc/module.xml
You will need to write the above mentioned code along the path mentioned to declare the module.
Configure the Module
Your next step is to configure the module, Magento_Hello that you have just created. You will need to create a controller and an action.
Create a file index.php along the following path
index, the folder is the controller while the file index.php is the action in this case. You will need to use execute () function to control the action
Here's the code that will trigger the action for this module
class Index extends \Magento\Framework\App\Action\Action
public function execute()
Create a Block
You will need to create a block in order to configure the module.
Go to app/code/Magento/Hello/Block/Hello.php
Paste the following code to this path
class Hello extends \Magento\Framework\View\Element\Template
public function _prepareLayout()
Write the Configuration File
Here, config.xml will configure the default configuration within tag
The frontend router information will be placed in the following path
The front end event will be declared along the following path
As mentioned the routers are declared using the following code in
Create Frontend Template
You will need to write the layout file to the following path
The layout file uses the nomenclature based on its structure
router name_controlle namer_action name
Here's the code for the layout file
Now, create a file success.phtml to the following path
This will act as the reporting file, which will announce the successful creation of a module
Activate the Module
Finally, you will need to activate the module by opening the config file app/etc/config.xml
In the array module, add the element Magento_Hello=>1
You will need to run the following link to see your module live
Creating a simple module certainly differs from Magento 1.0, but follows similar steps. You will see that creating a module is quite easy and effortless. You just need to remember the structure and should give a valid nomenclature to the module right when you are creating it.