cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a simple 'Hello World' module in Magento?

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to create a simple 'Hello World' module in Magento?

Hi,

 

How to create an "Hello World" using a controller / view / model approach. Any information about Magento 's code will be very helpful.

 

Thanks in Advance

Sarika
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: How to create a simple 'Hello World' module in Magento?

Here is steps by what i guided:
1. Module declaration: Create new xml file in app/etc/modules/M4U_HelloWorld.xml
<?xml version="1.0"?> <config> <modules> <M4U_HelloWorld> <active>true</active> <codePool>local</codePool> </M4U_HelloWorld> </modules> </config>

  1. Module configuration
    2.1. Create controller class in app/code/local/M4U/HelloWorld/controllers/IndexController.php

    class M4U_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(array('default')); $this->renderLayout(); } }

2.2. Create Block class in app/code/local/M4U/HelloWorld/Block/HelloWorld.php

class M4U_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template
                  {
                       // necessary methods
                  }

2.3. Create configuration xml in app/code/local/M4U/HelloWorld/etc/config.xml

<?xml version="1.0"?>
<config>
<global>
    <modules>
            <m4u_helloworld>
                    <version>0.1.0</version>
            </m4u_helloworld>
    </modules>
<blocks>
        <helloworld>
            <rewrite>
     <helloworld>M4U_HelloWorld_Block_HelloWorld</helloworld>
    </rewrite>
        </helloworld>
 </blocks>
    </global>
   <frontend>
            <routers>
                    <helloworld>
                            <use>standard</use>
                            <args>
                                  <module>M4U_HelloWorld</module>
                                  <frontName>helloworld</frontName>
                            </args>
                    </helloworld>
            </routers>
    <layout>
        <updates>
            <helloworld>
                  <file>helloworld.xml</file>
            </helloworld>
        </updates>
        </layout>
    </frontend>

 

  1. Define frontend template
    3.1. Define page layout in app/design/frontend/default/default/layout/helloworld.xml
    <?xml version="1.0"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="root"> <action method="setTemplate"> <template>page/1column.phtml</template></action> </reference> <reference name="content"> <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/> </reference> </helloworld_index_index> </layout>

  2. Create template file in app/design/frontend/default/default/template/helloworld/helloworld.phtml

Digital Marketer at Magento Development Company

View solution in original post

Re: How to create a simple 'Hello World' module in Magento?

Thank you, The information shared above  is of great help.

Sarika

View solution in original post

3 REPLIES 3

Re: How to create a simple 'Hello World' module in Magento?

Hello @sarika_aerolla

 

I don't why you are learning magento 1 now. 

 

Based on question check below link:-

https://inchoo.net/magento/programming-magento/magento-hello-world-module-extension/

 

i am preferring below url :-

http://excellencemagentoblog.com/blog/2011/09/22/magento-part4-series-helloworld/

( There are several part of that)

 

Hope it will help you.

 

if help you then mark as solution.

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to create a simple 'Hello World' module in Magento?

Here is steps by what i guided:
1. Module declaration: Create new xml file in app/etc/modules/M4U_HelloWorld.xml
<?xml version="1.0"?> <config> <modules> <M4U_HelloWorld> <active>true</active> <codePool>local</codePool> </M4U_HelloWorld> </modules> </config>

  1. Module configuration
    2.1. Create controller class in app/code/local/M4U/HelloWorld/controllers/IndexController.php

    class M4U_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(array('default')); $this->renderLayout(); } }

2.2. Create Block class in app/code/local/M4U/HelloWorld/Block/HelloWorld.php

class M4U_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template
                  {
                       // necessary methods
                  }

2.3. Create configuration xml in app/code/local/M4U/HelloWorld/etc/config.xml

<?xml version="1.0"?>
<config>
<global>
    <modules>
            <m4u_helloworld>
                    <version>0.1.0</version>
            </m4u_helloworld>
    </modules>
<blocks>
        <helloworld>
            <rewrite>
     <helloworld>M4U_HelloWorld_Block_HelloWorld</helloworld>
    </rewrite>
        </helloworld>
 </blocks>
    </global>
   <frontend>
            <routers>
                    <helloworld>
                            <use>standard</use>
                            <args>
                                  <module>M4U_HelloWorld</module>
                                  <frontName>helloworld</frontName>
                            </args>
                    </helloworld>
            </routers>
    <layout>
        <updates>
            <helloworld>
                  <file>helloworld.xml</file>
            </helloworld>
        </updates>
        </layout>
    </frontend>

 

  1. Define frontend template
    3.1. Define page layout in app/design/frontend/default/default/layout/helloworld.xml
    <?xml version="1.0"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="root"> <action method="setTemplate"> <template>page/1column.phtml</template></action> </reference> <reference name="content"> <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/> </reference> </helloworld_index_index> </layout>

  2. Create template file in app/design/frontend/default/default/template/helloworld/helloworld.phtml

Digital Marketer at Magento Development Company

Re: How to create a simple 'Hello World' module in Magento?

Thank you, The information shared above  is of great help.

Sarika