How to create custom module in magento

Home / Magento / How to create custom module in magento

Magento is best eCommerce system now a days which is offering rich customization possibilities by extensions and modules. Magento is built on a fully modular model that influences an unlimited scalability and flexibility for your store.

Make Custom Module Magento

There are many things custom modules can do, from editing your Database, to handling module upgrades to overriding classes (Blocks, Controllers, Models) … and more! Magento is an open source solution. So you can write new modules for Magento by yourself. Here I want to show you how to create simple costume module magento.

In Magento all modules are organized under a package. This package is nothing but a simple folder under codepool containing different modules. For example all core modules of magento system is kept under package “Mage” (open the folder /app/code/core/ , you see the folder “Mage” under which all system module resides).

Step 1: Create an xml file for modules declaration app/etc/modules/Just_Webdevelopment.xml

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

Step 2: Module Configuration

=> Create a controller class app/code/local/Just/Webdevelopment/controllers/IndexController.php

<?php
class Just_Webdevelopment_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
  		$this->loadLayout();    
  		$this->renderLayout();
    }
}
?>

=> Create a Block class app/code/local/Just/Webdevelopment/Block/webdevelopment.php

<?php
class Just_Webdevelopment_Block_Webdevelopment extends Mage_Core_Block_Template
{
	  // necessary methods
}
?>

=> Create a Helper class app/code/local/Just/Webdevelopment/Helper/Data.php

<?php
class Just_Webdevelopment_Helper_Data extends Mage_Core_Helper_Abstract
{
 
}
?>

=> Create configuration xml in app/code/local/Just/Webdevelopment/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Just_Webdevelopment>
            <version>0.1.0</version>
        </Just_Webdevelopment>
    </modules>
    <frontend>
        <routers>
            <webdevelopment>
                <use>standard</use>
                <args>
                    <module>Just_Webdevelopment</module>
                    <frontName>webdevelopment</frontName>
                </args>
            </webdevelopment>
        </routers>
        <layout>
            <updates>
                <webdevelopment>
                    <file>webdevelopment.xml</file>
                </webdevelopment>
            </updates>
        </layout>
    </frontend>
    <global>
        <models>
            <webdevelopment>
                <class>Just_Webdevelopment_Model</class>
                <resourceModel>webdevelopment_mysql4</resourceModel>
            </webdevelopment>
            <webdevelopment_mysql4>
                <class>Company_Web_Model_Mysql4</class>
                <entities>
                    <webdevelopment>
                        <table>webdevelopment</table>
                    </webdevelopment>
                </entities>
            </webdevelopment_mysql4>
        </models>
        <resources>
            <webdevelopment_setup>
                <setup>
                    <module>Just_Webdevelopment</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </webdevelopment_setup>
            <webdevelopment_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </webdevelopment_write>
            <webdevelopment_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </webdevelopment_read>
        </resources>
        <blocks>
            <webdevelopment>
                <class>Just_Webdevelopment_Block</class>
            </webdevelopment>
        </blocks>
        <helpers>
            <webdevelopment>
                <class>Just_Webdevelopment_Helper</class>
            </webdevelopment>
        </helpers>
    </global>
</config>

Step 3: Define Frontend Template

=> Define page layout in app/design/frontend/default/default/layout/webdevelopment.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
    </default>
    <webdevelopment_index_index>
		 <reference name="root">
            <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="webdevelopment/webdevelopment" name="webdevelopment" template="webdevelopment/webdevelopment.phtml" />
        </reference>
    </webdevelopment_index_index>
</layout> 

=> Create template file app/design/frontend/default/default/template/webdevelopment/webdevelopment.phtml

<?php
 echo "Welcome msg here ....";
?>

At last remove your all cache file from var/cache folder and then open URL on your browser
http://www.DomainName/ProjectName/index.php/webdevelopment/

If you want to download this module code please click here

Related Posts

Leave a Reply

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