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
9 Responses to “Howto: Repackageable custom extension development in Magento”
Leave a Reply
Most Popular
- HOWTO: PHP and jQuery upload progress bar (48)
- JQuery Progress Bar 1.1 (42)
- Howto: Repackageable custom extension development in Magento - Part 2 - Admin Controller (24)
- Howto: Repackageable custom extension development in Magento - Part 8 - CRUD - Update (16)
- HOWTO: struts 2 i18n (13)
- JQuery Progress Bar 2.0 (12)
- JQuery Progress Bar 1.2 (11)
- Howto: Repackageable custom extension development in Magento (9)
- Howto: Repackageable custom extension development in Magento - Part 3 - Database (9)
- Howto: Repackageable custom extension development in Magento - Part 9 - Frontend - List (8)
Recent Comments
- learning methods: All the posts you talk
- best travel agency: Wow! I really enjoyed this
- Muzafar Ali: Hi, thanks for sharing a beautiful
- andy65007: After the progress bar
- Mark: Excellent tutorials. Most "how to
- Mark: As Jim said before, you
- Jeremy Roberts: I tried and it works
- Silas Nordes: Came to this site by
- 150cc mopeds: That was a superb blog
- Jason: if the situation is like
Latest Entries
- jQuery Progress Bar Configuration
- Extracting email addresses from inbox
- 10 Good (Free and Legal) Source for Photos and Images
- Howto: Backup Microsoft SQL Server Database, as in Dump it to a SQL Script (like MYSQL's sqldump)
- Managing client's expectation with wireframe software
- Howto: Repackageable custom extension development in Magento - Part 9 - Frontend - List
- JQuery Progress Bar 2.0
- HOWTO: Find icons for your new prototype system
- Google Maps Helper
- laying the cornerstones

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.
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