2

The question I am sharing here is not about creating an extension, but about the order in which we should proceed.

This question will help a lot of people who want to create extensions. Because whenever we are creating an extension we usually try to check the impact our code has done so far.

So the question here is while creating an extension in magento which file/folder should be created in the order of first to last.

Also the extension I am talking about here, is a basic admin extension, with a tab in header in admin as well.

6
  • It depends. Most of the time we start with creating etc/config.xml and module activation file. This guide will have more info info.magento.com/rs/magentocommerce/images/…
    – Sukeshini
    Commented Jun 11, 2014 at 3:44
  • @Sukeshini Yes, I am aware of the documentation, but I would like be added here, is that core steps on stack itself, so that the shortest steps should be shared not the entire pdf. That is why I shared an example of just a basic extension. Commented Jun 11, 2014 at 6:12
  • I don't think there is a right way of doing it. of course, in order for your module to work you need app/etc/modules/[Namespace]_[Module].xml and app/code/[codepool]/[Namespace]/[Module]/etc/config.xml. But from there it's your choice. Or for simple CRUD modules you can use a module creator and everything is done at the same time.
    – Marius
    Commented Jun 11, 2014 at 6:38
  • @Marius, Thanks for the comment, and sure Module creator is an excellent piece of and we all respect you for that :). What I wanted to know, or rather wanted to be displayed here a small code of how to proceed, so that even a beginner can understand whats going on with what he is writing, instead of copying and pasting code from documentations/tutorials. I hope my point make sense. Commented Jun 11, 2014 at 6:42
  • 1
    @TBIInfotech. I wasn't talking about my module creator. I was talking about one in general. There are a lot of them out there, all of them do a nice job and saves you the trouble and boredom of doing the same thing over and over again. but I understand your point. It makes sense. Unfortunately I don't have a procedure for that. I'm not sure that I even know anymore how to create a CRUD module "by hand".
    – Marius
    Commented Jun 11, 2014 at 7:11

1 Answer 1

2

Step 1: Module Declaration Create app/etc/modules/M4U_HelloWorld.xml and write below code

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

Step 2: Module Configuration

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();
    }
}

b. Create a Block class

app/code/local/M4U/HelloWorld/Block/HelloWorld.php

class M4U_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template { // necessary methods }

c. 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>
</config>

Define Frontend Template :

  1. Define page layout in app/design/frontend/M4U/default/layout/helloworld.xml

N.B: Use default instead of M4U as template location if you use default design packages. Means create file 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>
  1. Create template file app/design/frontend/M4U/default/template/helloworld/helloworld.phtml and write down

N.B: Use default instead of M4U as template location if you use default design packages. Means create file in app/design/frontend/default/default/template/helloworld/helloworld.phtml

Hello World ! I am a Magento Guy..

Hey, new module is ready to run and hit browser with url

http://Yourdomain.com/projectname/index.php/helloworld/

and see result.

That’s it……..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.