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.

Ajaxform and Ajaxsubmit

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

1
2
3
4
5
6
7
8
9
<?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

1
2
3
4
5
6
7
8
9
10
<?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

1
2
3
4
5
6
<?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

1
2
3
4
5
6
<?php
class Just_Webdevelopment_Helper_Data extends Mage_Core_Helper_Abstract
{
 
}
?>

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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

1
2
3
4
5
6
7
8
9
10
11
12
13
<?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

1
2
3
<?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/

Related Posts

Leave a Reply

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