Home » Magento Customization, Magento Guide

Getting started with building Admin module in Magento

6 October 2009 No Comment

Getting started with building Admin module in Magento

Due to the “complexity” of Magento’s xml files, developers can waste great amount of time on “unnecessary” things.
When I say “complexity” I say it with purpose. XML files are not so complex by them selves, but due to extreme lack of documentation and changes Magento pumps in every new “major” release, people are lost among things that should really be sideways. Anyway, in this little article I will show you how to create basic, startup structure for your module to get it shown under Magento Admin main top menu.

As you can see on the picture below, I am creating a menu item with title “ActiveCodeline_SampleModule1″.

m1

My module is called “SampleModule1″ and it consists of just a few files. As you go over the provided config.xml file you will see that I used “BigLettersSmallLetters” style. I do this intentionally because this “naming convention” is another great pitfall for developers when it comes to constructing xml files. I know I too still struggle with “what must be the lowercase” question.

Here is my example of config.xml file

<pre>< ?xml version="1.0"?>

<config>
    <modules>
        <activecodeline_samplemodule1>
            <version>0.1.0</version>
        </activecodeline_samplemodule1>
    </modules>

<global>
        <helpers>
            <samplemodule1>
                <class>ActiveCodeline_SampleModule1_Helper</class>
            </samplemodule1>
        </helpers>
</global>        

        <admin>
        <routers>
            <samplemodule1>
                <use>admin</use>
                <args>
                    <module>ActiveCodeline_SampleModule1</module>
                    <frontname>samplemodule1</frontname>
                </args>
            </samplemodule1>
        </routers>
    </admin>

    <adminhtml>
        <menu>
            <menu1 translate="title" module="SampleModule1">
                <title>ActiveCodeline SampleModule1</title>
                <sort_order>60</sort_order>
                <children>
                    <menuitem1 module="SampleModule1">
                        <title>Menu item 1</title>
                        <action>samplemodule1/example</action>
                    </menuitem1>
                </children>
            </menu1>
        </menu>
        <acl>
            <resources>
                <admin>
                    <children>
                        <menu1 translate="title" module="SampleModule1">
							<title>ActiveCodeline SampleModule1</title>
                			<sort_order>60</sort_order>
                            <children>
                                <menuitem1>
                                    <title>Menu item 1</title>
                                </menuitem1>
                            </children>
                       </menu1>
                   </children>
               </admin>
           </resources>
        </acl>
    </adminhtml>    

</config>
</pre>

My “admin” controller is extremely simple, just an indexAction() method. However it does tell a lot. Below is a code of indexAction() method.

...
public function indexAction()
{
// &quot;Fetch&quot; display
$this->loadLayout();

// &quot;Inject&quot; into display
// THe below example will not actualy show anything since the core/template is empty
$this->_addContent($this->getLayout()->createBlock('core/template'));

// echo &quot;Hello developer...&quot;;

// &quot;Output&quot; display
$this->renderLayout();
}
...

And below are all the files required for this “Admin example module” to work.

Download Admin example module aka SampleModule1

Note this is only example, DO NOT USE on live site.

Cheers…

By Branko Ajzele from Inchoo.net

Related posts:

  1. CoolDash – Blank Magento extension for building admin system configuration area
  2. Observer pitfalls of building serious modules in Magento
  3. Adding a new tab under one page checkout – full working module
  4. Magento custom emails
  5. Access denied in Magento admin

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Security Code: