This entry was posted on Monday, June 22nd, 2009 at 3:47 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.
Jun 22, 2009
Howto: Repackageable custom extension development in Magento – Part 9 – Frontend – List
Author: gaweee | Filed under: development, howto Frontend – List
Let us revisit our frontend controller. Surely by now you’ve gotten a better grasp of the controller and models. So we’ll be revisiting those concepts here. So lets say you want to allow users to view you current Twits as well as create a new Twit.
- Some new file structure loving
app/ design/ frontend/ default/ default/ template/ twit/ - twits_list.phtml etc/ modules/ - SavantDegrees_All.xml (Or what ever your company name might be) code/ local/ SavantDegrees/ (Or what ever your company name might be) Twit/ (Or whatever your module name might be) Block/ Admin/ - Main.php Main/ - Grid.php - Edit.php Edit/ - Form.php - New.php New/ - Form.php - Index.php controllers/ - AdminController.php - IndexController.php etc/ - config.xml Helper/ - Data.php Model/ - Twit.php Mysql4/ - Twit.php Twit/ - Collection.php sql/ twit_setup/ - mysql4-install-0.2.0.php - mysql4-upgrade-0.1.0-0.2.0.phpWe’ve added a whole nasty branch of subdirectories under
app/designs. Read on to understand what its all for… - Let us return to our
IndexController.php<?php class SavantDegrees_Twit_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(); $this->getLayout() ->getBlock('content')->append( $this->getLayout()->createBlock('twit/index') ); $this->renderLayout(); } }
Hold your horses, this code is EXACTLY the same as the Part 1. Its just a revision. However, that being said, we see that in Part 1, we made the system create a
Blockcalledindex. That’s an opening… - So let us modify our
index.phpblock:<?php class SavantDegrees_Twit_Block_Index extends Mage_Core_Block_Template { public function __construct() { parent::__construct(); $this->setTemplate('twit/twits_list.phtml'); } public function getTwits() { $model = Mage::getModel('twit/twit'); $collection = $model ->getCollection() ->load(); return $collection->getItems(); } }
What the difference here? We made the block load the template from
twits/twit_list.phtml. We can create/find this file in/app/design/frontend/default/default/template/twits/twit_list.phtml. Some explanation is due here:- When you say
setTemplatein the block, it means, use this file as the presentation/view - This file exists in the some subdirectory of
/app/design/frontend/default/default/template. That is the path to your default template. Even though you may have other templates, this is the default 1. So when Magento cant find your template file in the other template directories, it always reverts back to this folder. Its a directory form of inheritance/ancestory/precedence.
- When you say
- Lastly, the
twit_list.phtmlfile:<?php $_twits = $this->getTwits(); if ($_twits) { $count = 0; foreach ($_twits as $i=>$twit) { ?> <div class="twit"> <div class='name'><?= $twit->getName() ?></div> <div class='summary'><?= $twit->getSummary() ?></div> </div> <?php } } ?>Since the whole purpose of
twits_list.phpis to prepare the view for the list of twits, it obviously needs to get the data from somewhere. It turns out, theTemplateis the extension of theBlock. So by calling$this->getTwits(), we’re calling theBlock'sgetTwits()method. - There you have it! check your twits list at http://127.0.0.1/magento/index.php/twit
6 Responses to “Howto: Repackageable custom extension development in Magento – Part 9 – Frontend – List”
Leave a Reply
Most Popular
- HOWTO: PHP and jQuery upload progress bar (47)
- JQuery Progress Bar 1.1 (41)
- Howto: Repackageable custom extension development in Magento - Part 2 - Admin Controller (24)
- Howto: Repackageable custom extension development in Magento - Part 8 - CRUD - Update (13)
- HOWTO: struts 2 i18n (12)
- JQuery Progress Bar 2.0 (11)
- JQuery Progress Bar 1.2 (10)
- Howto: Repackageable custom extension development in Magento - Part 3 - Database (9)
- Howto: Repackageable custom extension development in Magento (8)
- Howto: Repackageable custom extension development in Magento - Part 5 - CRUD - Retrieve (6)
Recent Comments
- donald: Hi Wen, I have checked out
- donald: Hi Ashley, Currently, I simply use
- donald: Hi Noemi, there are many
- Serge: Thanks a lot. It's the simplest
- Zoran: Excellent posts you got here...
- Craig: Brilliant tutorial! There's NOTHING on
- Will: Thnak you! I was
- Margots: Thank you a lot for
- Aswin S: Wow great dude.. For the
- Noemi Heier: This is great! How did
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
January 25th, 2010 at 6:11 pm
Excellent posts you got here… actually this is the best i could find about Magento, i am new at Magento but will start work at company pretty soon and main job will be Magento, i am still fighting around with the code, but your tutorial explains so much, though i have some questions, i need to look at the code first and try to cook it myself then will bother you
.
Thanks again
Zoran
January 7th, 2010 at 4:05 pm
Brilliant tutorial! There’s NOTHING on the web that I have found that goes into this much depth. I really think I can now do a bit of Magento development. Thanks gaweee!
November 17th, 2009 at 5:31 pm
This series is fantastic, and I recommend it to everyone who wants to develop a module with CRUD functionality, but I do have a bit of a request. I’ve followed this series and have created a working module, but now I would like to create roles that can access only this module. I’m having a hard time getting this working. Any advice or chance of an additional article on the subject? Thanks,
-Colin
October 22nd, 2009 at 7:07 pm
Thank you for this how-to. It has been more than helpful to get started in the complex world of Magento and the Zend Framework. And to think that I thought I could program in PHP…
September 15th, 2009 at 1:10 am
I hope it can function without any error.. Its helps…
June 22nd, 2009 at 3:51 am
[...] And we’re finally finally finally done! To test out the edit function, simply click on any row from the Grid! Thats assuming of course that you actually have some data. For frontend stuff, carry on … Fontend – List [...]