The module is fundamentally an element in the structure in Magento 2. A brand new system is built around modules part of Magento 2. The first step to building an individual eCommerce store is to build modules.
In this tutorial, we’ll help you follow a step-by-step guide to create a custom-built module. The steps you need to follow do the module:
Here’s the full procedure:
Step 1 Create the Magento/HelloWorld module folder within your app/code directory.
Step 2: Create etc/module.xml file.
Step 3. Create the registration.php file in the directory HelloWorld/Magento.
Step 4: Turn on the module.
Now let’s go with these steps in detail:
Step 1: Module name is defined as VendorName_ModuleName.
For instance:
Step 2: Create file module.xml in directory app/code/Magento/HelloWorld/etc
Step 3. Create the registration.php file within the directory HelloWorld/Magento.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
‘Magento_HelloWorld’,
__DIR__
);
?>
Step 4: Turn on the module by following:
After creating the module, you must run the command from the terminal. For example: PHP bin/Magento module:status
To turn on the module, execute the following command: PHP bin/Magento module: enable Magento_HelloWorld.
The module will be done in the following manner:
<?xml version=”1.0″?>
<!–
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
–>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:App/etc/routes.xsd”>
<router id=”standard”>
<route id=”helloworld” frontName=”helloworld”>
<module name=”Magento_HelloWorld” />
</route>
</router>
</config>
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\HelloWorld\Controller\Index;
use Magento\Framework\App\Action;
class Test extends Action
{
protected $_pageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
echo “Hello World Test Controller”;
exit;
}
}
?>