Mage Check Facebook iconFacebook MAGE CHECK Mage Check Linkedin iconLinkedin MAGE CHECK Mage Check Skype iconSkype MAGE CHECK

Magento How to create an extension module

$ To show you how to create a Magento extension, we are going to build a Tutorial module, which is going to have only the sample structure.

$ Let's follow the steps below!

Step 1: Declare Extension

Magento 1

<?xml version='1.0'?> <config> <modules> <MageCheck_Tutorial> <active>true</active> <codePool>local</codePool> </MageCheck_Tutorial> </modules> </config>

File path: app/etc/modules/MageCheck_Tutorial.xml

Magento 2

\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'MageCheck_Tutorial', __DIR__ );

File path: app/code/MageCheck/Tutorial/registration.php

Step 2: Create Configuration Files

Magento 1

<?xml version='1.0'?> <config> <modules> <MageCheck_Tutorial> <version>0.1.0</version> </MageCheck_Tutorial> </modules> <frontend> <routers> <tutorial> <use>standard</use> <args> <module>MageCheck_Tutorial</module> <frontName>tutorial</frontName> </args> </tutorial> </routers> </frontend> </config>

File path: app/code/local/MageCheck/Tutorial/etc/config.xml

Magento 2

File path: app/code/MageCheck/Tutorial/etc/module.xml

<?xml version='1.0'?> <config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='../../../../../lib/internal/ Magento/Framework/Module/etc/module.xsd'> <module name='MageCheck_Tutorial' setup_version='0.0.0'> </module> </config>

File path: app/code/MageCheck/Tutorial/etc/adminhtml/routes.xml

<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'xsi:noNamespaceSchemaLocation='../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd'> <router id='admin'> <route id='magecheck_tutorial' frontName='magecheck_tutorial'> <module name='MageCheck_Tutorial' /> </route> </router> </config>

Step 3: Create Function

Magento 1

<?php class MageCheck_Tutorial_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { echo 'Welcome to MageCheck Tutorials - Magento 1' . '<br><br>'; // call yourFunction(); } public function yourFunction() { // ... } }

File path: app/code/local/MageCheck/Tutorial/controllers/IndexController.php

Magento 2

<?php namespace MageCheck\Tutorial\Controller\Index; class Test extends \Magento\Framework\App\Action\Action { public function __construct( \Magento\Framework\App\Action\Context $context ){ return parent::__construct($context); } public function execute() { echo 'MageCheck Tutorial!'; } }

File path: app/code/MageCheck/Tutorial/Controller/Index/Test.php

Do not forget to clean the Magento Cache.

This is the sample way to create an Extension in Magento!

Contact us

Have you decided on an online Business Plan website?