Getting started with building Admin module in Magento
21 Comments 8th JUN 2009 | Posted by Branko Ajzele 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″.
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
< ?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>
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()
{
// "Fetch" display
$this->loadLayout();
// "Inject" into display
// THe below example will not actualy show anything since the core/template is empty
$this->_addContent($this->getLayout()->createBlock('core/template'));
// echo "Hello developer...";
// "Output" 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…
To post code in comments, place your code inside [code] and [/code] tags.


















June 8th, 2009 at 8:51
Nice skeleton template, thanks Branko.
I hope you’re going to play around in the admin some more
. It would be great to know how to create custom updateable attributes on the View Order page (like the Gift message update).
June 8th, 2009 at 14:07
hey, great article. would be nice if you add your skeleton to the module creator as a magento extension. we are trying to get a comprehensive collection of skeletons for developers for an easier start:
http://www.magentocommerce.com/extension/1108
October 13th, 2009 at 23:04
Choice big help. You’re right about the complexity of the xml files, I’m finding it extremely hard to pin point some clear documentation on developing for Magento.
October 13th, 2009 at 23:52
Aye? who stole whos article? someone has copied and pasted asia-connect.com.vn/2009/10/getting-started-with-building-admin-module-in-magento/
October 14th, 2009 at 7:29
@Lex: At the end of Asia-Connect’s article stands: By Branko Ajzele from Inchoo.net, hope that answers your question.
December 13th, 2009 at 13:49
But when I echo something, it doesnt show up where it is supposed to show up.. instead, it shows up before the tag..
December 18th, 2009 at 20:41
I am also a little confused, where do I add in my page stuff, the menu item shows up and takes me to a page but it has no content what files do I need to add?
December 19th, 2009 at 23:32
thank you, thanks you * 10000000,
this magento xml thing drive me crazy ,
you save my day,
January 12th, 2010 at 18:10
Thanks, seeing and testing the code is a lot easier way to learn how to develop modules in Magento. Big Thanks!
January 13th, 2010 at 9:19
Aren’t you supposed to specify the block and template (.phtml) in the local.xml file? Instead of activating it with the controller?
See:
http://alanstorm.com/2009/img/magento-book/magento-mvc.png
January 26th, 2010 at 1:19
The sample file is a mystery to me. I have all the tools: zip,gz,tar etc.
Can somebody jot down the steps to unpack this please?
February 11th, 2010 at 17:48
To upack the file:
download the tar.gz file and extract
the next file is a tar file but the the period is not between the filename and the tar, should be samplemodule1.tar
extract that
the next file should be a zip file, need to add the .zip extension
opened right up…
hope this helps…
February 24th, 2010 at 6:54
Great Tutorial Mate!
But can you please describe little bit more if we want to add a big module in Administration!
Actually i am builidng this http://www.getmybrand.com website and need to add new module within its front end and back end!
Any help would be appreciated!
Regards,
Raj
May 15th, 2010 at 14:12
it is better in system.xml?
May 28th, 2010 at 9:08
Hi,
i can’t download the above attached file “Admin example module aka SampleModule1″.
May 28th, 2010 at 9:15
i can’t extract the above attached file. please help me to open this file
May 28th, 2010 at 9:22
@shylaja Please use the winRar if on windows or unarchiver if on mac. I’ve downloaded and extracted the file without a problem on both machines. What might be the problem is that your software doesn’t decompress the file completely since this is a tar.gz compression.
June 22nd, 2010 at 19:14
I can’t extract the file either.. it says that it’s corrupt
June 22nd, 2010 at 19:16
Never mind.. after following @jbatson instructions I was able to get it open
July 14th, 2010 at 21:31
Anyone had a success, displaying a grid report without creating a new table but retreive just the sales that are being processed?
August 10th, 2010 at 9:15
Hi, i have created a module in admin section and setup link in admin top menu, while i clicks on it i go to my controller and get the header and footer part of the admin section but not getting the middle part.
I put my XML file for layout in adminhtml/…./layout directory and phtml file also at adminhtml/…./template. but getting the blank page implace of my layout page, is any body have any document or any thing that can help me
Thank you