In this tutorial we will learn the fundamental aspect of being a Magento 2 developer, namely customising Magento 2 with your own modules. This is a basic module that will get you started on the road to bigger and better things!
What files does a Magento 2 module need?
The following are the minimum files required by a Magento 2 module
- registration.php file
- etc/module.xml file
- composer.json file (This is only required if your code will be managed by composer)
Creating our basic module
Lets first create a folder in ROOT_MAGENTO_FOLDER/app/code using the name “Novxweb”. Inside this folder create another folder called “Helloworld”.
All modules need a namespace and module name. In this case our namespace will be “Novxweb” and our module name will be “Helloworld”.
Creating our registration.php file
In Novxweb/Helloworld create a file called registration.php and paste in the following code:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE, 'Novxweb_Helloworld',
__DIR__
);
Creating our module.xml file
In Novxweb/Helloworld/etc create a file called module.xml and paste in the following code
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Novxweb_Helloworld" setup_version="0.0.1">
</module>
</config>
Installing the module
Using ssh change directory to the root of the Magento installation and then issue the command
bin/magento setup:upgrade
In the output you should see your module “Novxweb_Helloworld”. That’s it! you have created a Magento 2 module.
This was a very a basic module that we will need to build on to make it do something useful.