How to create your own custom module or extension in magento

Magento

Posted on 02 Jun 15 by Vickey
  820



From magento community we can install many extension or module.These module provided by magento connect and from third party developers. By these modules or extension we can solve many difficult task without programming.But if we are working on specific task which is not available on magento community then we need to create our own module with own logic. but for creating own custom module there is need good programming skill and good knowledge of magento structure.

All types of modules located in "/app/code" folder here are three types of module 1.Core: Here are the core functionalites stored which come inbuilt with magento installation 2.Community: These comes from third party developers which are paid and free 3.Local: Here we create our custom module

Lets strat ton create custom module

First go to directory " /app/code/" and create a directory name as "local" if not exist now open local directory and here we will create a new directory which will be the name space of our module for example i am creating it with my name "Vickey" don't use underscore or space in this name. now open namespace directory and create a subdirectory and give a name which will be the module name i am giving name "Hello". now we have namespace "Vickey" and module name "Hello".For use this module property we need to declear the module.

go to "/app/etc/modules" and create a xml file with the name of namespace and module name for example Vickey_Hello.xml

and add the code like this

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

Now go to directory "/app/code/local/Vickey/Hello" and create a directory "controllers" open this and create a file "IndexController.php" and put the below code in this file

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

after creating controller again go to "/app/code/local/Vickey/Hello" create directory Block and create a file "Hello.php" and put code

<?php
class Vickey_Hello_Block_Hello extends Mage_Core_Block_Template
{
  methods
}

?>
create a file "/app/code/local/Vickey/Hello/etc/config.xml" and put code
<?xml version="1.0"?>
<config>
    <global>
        <modules>
                <vickey_hello>
                        <version>0.1.0</version>
                </vickey_hello>
        </modules>

    <blocks>
            <hello>
                <rewrite>
         <hello>Vickey_Hello_Block_Hello</hello>
        </rewrite>
            </hello>
     </blocks>

        </global>
       <frontend>
                <routers>
                        <hello>
                                <use>standard</use>
                                <args>
                                      <module>Vickey_Hello</module>
                                      <frontName>hello</frontName>
                                </args>
                        </hello>
                </routers>
        <layout>
            <updates>
                <hello>
                      <file>hello.xml</file>
                </hello>
            </updates>
            </layout>
        </frontend>
</config>

Now go to your theme which is set for your magento frontend

"/opt/lampp/htdocs/magento/app/design/frontend/my_theme/default/layout" and create a file "hello.xml" and add code

<?xml version="1.0"?>
    <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>

after completing saving this file go to directory "/app/design/frontend/my_theme/default/template" and create a subdirectory "hello" with a file name as hello.phtml and put something which you want to show on webpage and you have done now open your browser put url "your domain name/index.php/hello"

I hope this will help you to creating your first custom module

If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com