This entry was posted on Tuesday, March 31st, 2009 at 4:07 am and is filed under development, howto. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Mar 31, 2009
Howto: Repackageable custom extension development in Magento
Author: gaweee | Filed under: development, howtoMagento needs no explaning, but it does need a shitload of proper developers education. So much that our team spent a good amount of time trying to learn how to develop on the damn thing. So heres a synthesized description of our efforts. We’re breaking up this HOWTO into a few segments into increasing orders of complexity and integration.
Let us begin …
Setup Module Environment and Helloworld
We’re trying to achieve a proof of concept here to describe how the file structure, namespaces and config files interplay to achieve a Hello world message
- Create your directory structure! Our NEW company name is Savant Degrees! and our module shall be called….. Twits (for a lack of an imagination). The whole module (well, almost) should rest in the
/app/code/local>folder. So lets first create the following folder structure. For a hello world module, you only need aconfigfile, acontrollerand ablock. Ergo…app/ etc/ modules/ - SavantDegrees_All.xml (Or what ever your company name might be) code/ local/ SavantDegrees/ (Or what ever your company name might be) Twits/ (Or whatever your module name might be) Block/ - HelloWorld.php controllers/ - IndexController.php etc/ - config.xml - Create your
config.xmlfile. Thats the crux of the whole module.<?xml version="1.0"?> <config> <modules> <SavantDegrees_Twits> <version>0.1.0</version> </SavantDegrees_Twits> </modules> <global> <blocks> <twits> <class>SavantDegrees_Twits_Block</class> </twits> </blocks> </global> <frontend> <routers> <SavantDegrees_Twits> <use>standard</use> <args> <module>SavantDegrees_Twits</module> <frontName>twits</frontName> </args> </SavantDegrees_Twits> </routers> </frontend> </config>
Let me explain this step a little…
The
modules > [module] > versionnumber allows Magento to track when your module is upgraded. We’ll be seeing a version of that shortly.
Theglobal > blocks > [module]define the Block resources that are available under your package. We’ll be using this to generate a Hello world shortly
Thefrontend > routersfragment define how the module can be access. The current code allows the block to be access via https://127.0.0.1/magento/index.php/twits - Create your
IndexController.phpfile. Its as simple as:class SavantDegrees_Twits_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(); $this->getLayout() ->getBlock('content')->append( $this->getLayout()->createBlock('twits/helloWorld') ); $this->renderLayout(); } }
More Explanation: The
twits/indexrefers to the index block inside the Twits module, which is defined in the config file above. We’re trying to put its contents inside the layout. - Lastly, we’ll create the
Index.phpBlock:class SavantDegrees_Twits_Block_HelloWorld extends Mage_Core_Block_Template { protected function _toHtml() { return 'Hello world'; } }
You DO understand SOME PHP don’t you?
- Finally, we activate the module by creating the file
SavantDegrees_All.xmlfile<?xml version="1.0"?> <config> <modules> <SavantDegrees_Twits> <active>true</active> <codePool>local</codePool> </SavantDegrees_Twits> </modules> </config>
- Wake up the Magento installer by logging into the
adminbackend,System > Configuration > Advanced > Advanced. Click onSave Config. Clear your cache at/var/cachetoo just to be sure.
Tada! Navigate to https://127.0.0.1/magento/index.php/twits to see your well deserved Hello World!
» Next … Part 2 – Admin Controller
read users' comments (12)
12 Responses to “Howto: Repackageable custom extension development in Magento”
Leave a Reply
Most Popular
- HOWTO: PHP and jQuery upload progress bar (56)
- JQuery Progress Bar 1.1 (53)
- Howto: Repackageable custom extension development in Magento - Part 2 - Admin Controller (25)
- JQuery Progress Bar 2.0 (21)
- Howto: Repackageable custom extension development in Magento - Part 8 - CRUD - Update (18)
- HOWTO: struts 2 i18n (16)
- Howto: Repackageable custom extension development in Magento (12)
- JQuery Progress Bar 1.2 (11)
- Howto: Repackageable custom extension development in Magento - Part 9 - Frontend - List (10)
- Howto: Repackageable custom extension development in Magento - Part 3 - Database (9)
Recent Comments
- Karen: Great work around-thank you!!
- Sheldon: awesome possum!
- cmstop里所使用的有用的jquery插件 » Terry's Blog: [...] http://t.wits.sg/jquery-progress-bar/ 这篇日志的 t.cn [...]
- Lakshyami: Hi, Thank you very much for
- New site feature: User Poll « TechnoStripe: [...] progress bar used to
- seo agentur: @Krish Why do you need to
- 2kai: Hi Aromal, you need to flush
- Rob Rasner Magic Castle: I love what you guys
- รับทำเว็บไซต์: Thx for this. Nice and
- Lexus: ESxtYC I'm not easily impressed.
Latest Entries
- SD in the Community: Product Management Panel Recap
- Mac OS X and Ricoh Aficio C2051 - Making Printing "Just Work"
- How to impress your recruiter
- Thoughts on Attracting the attention of the Best Hires
- The Greg Syndrome
- The Parental Manager
- Attack of the Facebook Harvesters
- jQuery Progress Bar Configuration
- Extracting email addresses from inbox
- 10 Good (Free and Legal) Source for Photos and Images

November 9th, 2010 at 7:29 am
hi,
can someone explain how to edit the content from the front end,
here its only edited and saving only at the admin panel,
i want to save and edit from the front end.
August 23rd, 2010 at 3:21 pm
Thank you for your help . this tutorial was really useful for me .
June 8th, 2010 at 3:10 pm
As Jim said before, you have some case-sensitivity issues in your code above. Make sure IndexControler.php and HelloWorld.php start with upper-case letters (they still have lower-cased first characters in the directory tree).
This is pretty important for a system that heavily recommends installation on *NIX systems instead of Windows.
March 9th, 2010 at 2:03 am
hi gaweee
thanks a lot for your grate tutorial.
i was getting 404 error because of controllers directory name.
i given name Controllers instead of controllers now it’s fine .
thanks
January 25th, 2010 at 11:08 pm
Thanks a lot.
It’s the simplest way to start programming magento among those I’ve found in www
September 15th, 2009 at 11:03 am
go ahead man
thanks
i get the prob the problem was with th digram
September 15th, 2009 at 10:58 am
hello
thanks for your helpful . but i did what you explain >> i don’t know why i get ERROR 404
i tried to do it again >>> but the same prob i met
could you get me the reason if u can
May 8th, 2009 at 9:46 am
This is a very helpful guide. Thank you!
In my case I was getting a Magento error ‘Controller file was loaded but class does not exist’ until I noticed there was no opening ‘<?php’ in the IndexController.php file. I added that, voila! Progress.
April 12th, 2009 at 7:10 am
Thanks! I’ve updated the code to reflect those changes!
April 12th, 2009 at 6:49 am
o0o I worked it out … in your directory structure diagram you have indexController.php however later on in your code you have IndexController.php
notice the capital I… the I needs to be capital.. mine was lower case thanks again
err ps.. I posted this follow up on part 4 two by mistakes :$
April 12th, 2009 at 6:45 am
Hi there,
Thanks for a great tutorial, I’am having some troubles though…
I followed the tutorial on this page step by step for hello world… however changed the company and module name.. the new module shows up in config>advanced and is enabled, I then clear cache and tried to access it from demoshop/mymodname and I get the magento 404 message..
So I start over, not changing any names or anything.. keep the code exactly as you have it above… and it again appears in config as enabled, so I reset cache and try to access demoshop/twit and agian get the magento 404…
any assistance on this would be much thought of
many thanks,
Jim
April 1st, 2009 at 5:58 am
Thank you – you tutorial is the first one I found where everything just works and has a good explanation as well. Thanks again.
Claudia