Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Magento: Hello World Module

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 160
    Comment on it

    To start with module development in magento it is necessary to understand the file structure needed to create module. To understand the structure we are going to develop one hello world module to display content in front end.

    1) app/etc/modules/Evon_Hello.xml
    2) app/code/local/Evon/Hello/etc/config.xml
    3) app/code/local/Evon/Hello/controllers/IndexController.php
    4) app/design/frontend/your_theme/layout/hello.xml
    5) app/design/frontend/your_theme/template/hello.phtml

    Now, we will create files as per the structure defined.

    First we will create "Evon_Hello.xml" file in "app/etc/modules/" folder with the following content.

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

    Then, we will create module configuration file "config.xml" in "app/code/local/Evon/Hello/etc/" folder with the following content.

    <?xml version="1.0"?>
    <config>
        <modules>
            <Evon_Hello>
                <version>0.1.0</version>
            </Evon_Hello>
        </modules>
        <frontend>
            <routers>
                <hello>
                    <use>standard</use>
                    <args>
                        <module>Evon_Hello</module>
                        <frontName>hello</frontName>
                    </args>
                </hello>
            </routers>
            <layout>
                <updates>
                    <hello>
                        <file>hello.xml</file>
                    </hello>
                </updates>
            </layout>
        </frontend>
    </config>
    

    Then, we will create controller file "IndexController.php" in "app/code/local/Evon/Hello/controllers/" folder with the following content.

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

    Then, to show the content in frontend we need to create frontend layout file "hello.xml" in "app/design/frontend/your_theme/layout/" folder with the following content.

    <?xml version="1.0"?>
    <layout version="0.1.0">
        <hello_index_index>
            <reference name="content">
                    <block type="core/template" name="hello" template="hello/hello.phtml"/>
            </reference>
        </hello_index_index>
    </layout>
    

    Then, we will create file "hello.phtml" in "app/design/frontend/your_theme/template/hello/" folder with the following content. This is the file whose content will be shown in frontend under module URL.

    <?php
        echo "here";
    ?>
    

    Now, to see the content in frontend we will use the url "http://siteurl/hello/" .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: