Monday , April 24 2017
Home >> All tutorial >> How To Create A Simple Module

How To Create A Simple Module

Magento tutorial or beginners >> Magento extension tutorial:

Have you read magento tutorial: Install alpha version on online server ?

Well, to make a Magento website perfectly, we absolutely need to create many module. In this tutorial, I will give the easiest way to create a simple Magento module.

Now, let’s start!

1.  Create a simple module on Magento 1.x [magento tutorial]

First, we will remind how to create an extension on Magento 1.x: (Namespace: Magento, Module Name:  Hello)

Step 1:   Declare your module in folder:  app/etc/

<?xml version="1.0"?>
<config>
         <modules>
                <Magento_Hello>
                        <active>true</active>
                        <codePool>local</codePool>
                </Magento_Hello>
         </modules>
</config>

 

Step 2:  Module configuration

– Creat a controller : app/code/local/Magento/Hello/controllers/IndexController.php

class Magento_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
     $this->loadLayout();
     $this->renderLayout();
    }
}

 

– Creat a block :  app/code/local/Magento/Hello/Block/Hello.php

class Magento_Hello_Block_Hello extends Mage_Core_Block_Template
{
  // write function here
}

 

– Creat a configuration file config.xml :  app/code/local/Magento/Hello/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
       <Magento_Hello>
           <version>0.1.0</version>
       </Magento_Hello>
   </modules>
   <global>
   </global>
   <frontend>
       <routers>
           <magento_hello>
               <use>standard</use>
               <args>
                   <module>Magento_Hello</module>
                   <frontName>hello</frontName>
               </args>
           </magento_hello>
       </routers>
<layout>
           <updates>
               <hello>
                   <file>hello.xml</file>
               </hello>
           </updates>
       </layout>
   </frontend>
   <global>
 <blocks>
           <hello>
               <class>Magento_Hello_Block</class>
           </hello>
       </blocks>
   </global>
</config>

Step 3:  Create a Frontend Template

– Write a file layout : app/design/frontend/default/default/layout/hello.xml

<layout version=”0.1.0″>
    <hello_index_index>
      <reference name=”root”>
<action method=”setTemplate”><template>page/1column.phtml</template></action>
      </reference>
      <reference name=”content”>
 <block type=”hello/hello” name=”hello” template=”hello/hello.phtml”/>
      </reference>
   </hello_index_index>
</layout>

 

– Push/Place content to file template hello.phtml

When you can access http://localhost/magento20/hello/index/index to view this extension, you can see: “This is a simple module in Magento 1.0”


Ready to foster your knowledge with MAGENTO 2 BASIC GUIDE

The new Order Success combo with Magento 2 Inventory Management, Magento 2 Order Fulfillment, Magento 2 Dropship, Magento 2 Barcode Management and Magento 2 Purchase Management

Is your site still a mess and Magento extensions are not enough to save your site? Save your site with Magento Web Development Services now

magento services


About Champ

Leave a Reply

Your email address will not be published. Required fields are marked *