<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tips for Twits&#187; howto</title>
	<atom:link href="http://t.wits.sg/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://t.wits.sg</link>
	<description>WARNING: excessive use of this site will increase MP at the expense of HP</description>
	<lastBuildDate>Tue, 12 Jul 2011 15:09:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 9 &#8211; Frontend &#8211; List</title>
		<link>http://t.wits.sg/2009/06/22/howto-repackageable-custom-extension-development-in-magento-part-9-frontend-list/</link>
		<comments>http://t.wits.sg/2009/06/22/howto-repackageable-custom-extension-development-in-magento-part-9-frontend-list/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 07:47:13 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=327</guid>
		<description><![CDATA[Download the source for this entire series here! Frontend &#8211; List Let us revisit our frontend controller. Surely by now you&#8217;ve gotten a better grasp of the controller and models. So we&#8217;ll be revisiting those concepts here. So lets say you want to allow users to view you current Twits as well as create a [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3>Frontend &#8211; List</h3>
<p>Let us revisit our frontend controller. Surely by now you&#8217;ve gotten a better grasp of the controller and models. So we&#8217;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 Tip. </p>
<ol>
<li>Some new file structure loving

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">app/
  design/
    frontend/
      base/
        default/
          template/
            twits/
              - tip_list.phtml
  etc/
    modules/
      - SavantDegrees_All.xml <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
  code/
    local/
      SavantDegrees/ <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
        Twits/ <span style="color: #33cc33;">(</span>Or whatever your module name might be<span style="color: #33cc33;">)</span>
          Block/
            Admin/
              - Main.php
              Main/
                - Grid.php
              - Edit.php
              Edit/
                - Form.php
              - New.php
              New/
                - Form.php
            - HelloWorld.php
            - Index.php
          controllers/
            - AdminController.php
            - IndexController.php
          etc/
            - config.xml
          Helper/
            - Data.php
          Model/
            - Tip.php
            Mysql4/
              - Tip.php
              Tip/
                - Collection.php
          sql/
            twits_setup/
              - mysql4-install-0.2.0.php
              - mysql4-upgrade-0.1.0-0.2.0.php</pre></div></div>

<p>We&#8217;ve added a whole nasty branch of subdirectories under <code>app/designs</code>. Read on to understand what its all for&#8230;
</li>
<li>Let us return to our <code>IndexController.php</code>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_IndexController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Controller_Front_Action
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">append</span><span style="color: #009900;">&#40;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/index'</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>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 <code>Block</code> called <code>index</code>. That&#8217;s an opening&#8230;</li>
<li>So let us modify our <code>Index.php</code> block:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Index <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Block_Template
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip_list.phtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTips<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #000088;">$collection</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$model</span>
    	    	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    	    	<span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$collection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getItems</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What the difference here? We made the block load the template from <code>twits/tip_list.phtml</code>. We can create/find this file in <code>/app/design/frontend/default/default/template/twits/tip_list.phtml</code>. Some explanation is due here:
<ul>
<li>When you say <code>setTemplate</code> in the block, it means, use this file as the presentation/view</li>
<li>This file exists in the some subdirectory of <code>/app/design/frontend/default/default/template</code>. 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.
<li>
</ul>
</li>
<li>Lastly, the <code>tip_list.phtml</code> file:

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;?php
$_tips = $this-&gt;getTips();
if ($_tips) {
	$count = 0;
	foreach ($_tips as $i=&gt;$tip) {
?&gt;
		&lt;div class=&quot;tip&quot;&gt;
			&lt;div class='title'&gt;&lt;?= $tip-&gt;getTitle() ?&gt;&lt;/div&gt;
			&lt;div class='author'&gt;&lt;?= $tip-&gt;getAuthor() ?&gt;&lt;/div&gt;
			&lt;p&gt;&lt;?= $tip-&gt;getContents() ?&gt;&lt;/p&gt;
		&lt;/div&gt;
&lt;?php
	}
}
?&gt;</pre></div></div>

<p>Since the whole purpose of <code>tip_list.phtml</code> is to prepare the view for the list of tips, it obviously needs to get the data from somewhere. It turns out, the <code>Template</code> is the extension of the <code>Block</code>. So by calling <code>$this->getTips()</code>, we&#8217;re calling the <code>Block's</code> <code>getTips()</code> method.
</li>
<li>There you have it! check your tips list at <a href="http://127.0.0.1/magento/index.php/twits">http://127.0.0.1/magento/index.php/twits</a></li>
<div class="h_l">
<div></div>
</div>
<p>If it works for you, leave a comment! =)</p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/06/22/howto-repackageable-custom-extension-development-in-magento-part-9-frontend-list/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>JQuery Progress Bar 2.0</title>
		<link>http://t.wits.sg/2009/06/21/jquery-progress-bar-2-0/</link>
		<comments>http://t.wits.sg/2009/06/21/jquery-progress-bar-2-0/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 02:39:49 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[progressbar]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=320</guid>
		<description><![CDATA[Hi all its us again, In the past few months we&#8217;ve been asked many a times to help improve the progressbar code. We&#8217;ve also been referenced by several websites as THE progressbar to use. In all, we felt we owed it to you guys to make it better. So here we are, after all those [...]]]></description>
			<content:encoded><![CDATA[<div style="float: left; margin: 0px 10px 10px 0px;"><a href="http://t.wits.sg/wp-content/uploads/2008/06/jqueryprogressbar.jpg"><img class="alignnone size-medium wp-image-11" title="jQuery progressBar" src="http://t.wits.sg/wp-content/uploads/2008/06/jqueryprogressbar.jpg" alt="jQuery progressBar screenshot" width="200" height="200" /></a></div>
<p>Hi all its us again, In the past few months we&#8217;ve been asked many a times to help improve the progressbar code. We&#8217;ve also been referenced by several websites as THE progressbar to use. In all, we felt we owed it to you guys to make it better.</p>
<p>So here we are, after all those emails and bug reports, we finally got down to it. Always good to take a couple of months to have a fresh prespective of things. We ripped out the old code and made it much better and more extensible than its predecessors. So much that we decided it was enough to qualify as a major revision.</p>
<div style="clear: both">&nbsp;</div>
<p>Let see whats been done&#8230;</p>
<ul>
<li>Cleaned up the code, yes its lighter, cleaner faster. (Still lacks documentation though) <img src='http://t.wits.sg/wp-includes/images/smilies/icon_neutral.gif' alt=':|' class='wp-smiley' /> </li>
<li>Callbacks! Everyone&#8217;s favourite</li>
<li>Max values, you can now set it to be 150/2000 instead of just a percentage</li>
<li>Text formats. Show 75/100 or 75% by toggling the <code>textFormat</code> accordingly</li>
<li>Steps, how many steps to get to your target value</li>
<li>Step Duration, how long each step lasts</li>
<li>Webkit (Chrome/Safari) compatibility. More like, Webkit Hacks</li>
</ul>
<p>Once again, many a thanks for all those who have so generously provided the feature requests as well as bug fixes every now and then. And thanks for all your patience in waiting for this new release. <img src='http://t.wits.sg/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
If its working for you, drop us a comment and tell us where we can see your stuff!</p>
<p><strong>Download the new jQuery progressbar here: <a href="http://t.wits.sg/jquery-progress-bar/" target="_blank">jQuery progressbar<br />
</a>or view the demo <a href="http://t.wits.sg/misc/jQueryProgressBar/demo.php" target="_blank">here</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/06/21/jquery-progress-bar-2-0/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Google Maps Helper</title>
		<link>http://t.wits.sg/2009/06/14/google-maps-helper/</link>
		<comments>http://t.wits.sg/2009/06/14/google-maps-helper/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 13:51:15 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[maps]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=281</guid>
		<description><![CDATA[In our work we like to create Google Maps links for our client&#8217;s (offices, stores, etc). However, the larger our clients presence, the more random links there are bound to be. When it comes to using Google Map&#8217;s javascript API to control the map, thats still perfectly fine. But how do I create a google [...]]]></description>
			<content:encoded><![CDATA[<p>In our work we like to create Google Maps links for our client&#8217;s (offices, stores, etc). However, the larger our clients presence, the more random links there are bound to be. When it comes to using Google Map&#8217;s javascript API to control the map, thats still perfectly fine. But how do I create a google maps link that only shows 1 entry? Turns out, there are several ways to do this:</p>
<ol>
<li><strong>Manipulate the request such that it only shows your entry</strong>How? For example, searching for &#8220;Holland, Singapore&#8221; will lead us to about 1,356 results. See <a href="http://www.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=holland,+Singapore&amp;mrt=yp&amp;sll=1.305855,103.786876&amp;sspn=0.008055,0.016522&amp;ie=UTF8&amp;z=14">here</a>. So lets tweak it a little:
<ul>
<li>Append <code>&amp;mrt=yp</code> to the url &#8211; That returns us all the business listings. (852 results)</li>
<li>Append <code>&amp;start=16</code> to the url &#8211; That skips the first 16 results (Shows results 17-26 of 852)</li>
<li>Append <code>&amp;num=2</code> to the url &#8211; That returns us only 2 results (Only shows 2 results)</li>
</ul>
<p>For a more complete listing of Google Maps Parameters, consult <a href="http://mapki.com/wiki/Google_Map_Parameters">mapki.com</a>. Kudos to those guys for compiling that list. Really useful stuff<br />
So there you have it, a simple way to link your business such that its the only entry there. However this method is relatively dangerous. Why? Cause you&#8217;ve got no idea of the exact ordering that Google maps may return. Today you could be entry 17, surely not in a year (hopefully for the better). As such, this is not the recommended solution.</li>
<li><strong>Use the address with your long/lat coordinates to generate your entry.</strong>
<ul>
<li> First get your GPS coordinates, there are a number of ways to do this. Check our this <a href="http://en.wikipedia.org/wiki/Geographic_coordinates_(obtaining)">link</a></li>
<li>Then create your link via the following structure: <code>http://www.google.com/maps?&amp;ie=UTF8&amp;hl=en&amp;q=[urlescaped address]&amp;ll=[GPS lat,long]&amp;z=[Zoom]&amp;iwloc=A</code></li>
<li>Still too troublesome? We&#8217;ve created a simple tool for our clients to use. Save yourself some time.  <a href="http://t.wits.sg/misc/googleMapsHelper/demo.php">Try it!</a>
</li>
<p>Done! Whats the downside to this? <strong>You can only show the address for the business</strong>. Because searching by business names returns us way too many results. So instead, we have to search for an address, Google interprets this as an address and only returns 1 result (which is the whole point of geocoding). At this point its easy to the map to what we need. We&#8217;d use this typically for this nifty little &#8220;Find us on a map&#8221; links (instead of embedding the actual map on your site).</ul>
</li>
</ol>
<p>Once again, if you&#8217;d rather embed Google maps directly into your site via the JS, then your options are much more open.<br />
Good luck! Let us know if it works for you, of if you find a better way of doing things!<br />
<a href="http://t.wits.sg/misc/googleMapsHelper/demo.php"><img src="http://t.wits.sg/wp-content/uploads/2009/06/googleMapsHelper-300x291.png" alt="googleMapsHelper" title="googleMapsHelper" width="300" height="291" class="alignnone size-medium wp-image-314" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/06/14/google-maps-helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HOWTO: Controlling your presentation with your phone</title>
		<link>http://t.wits.sg/2009/04/13/howto-controlling-your-presentation-with-your-phone/</link>
		<comments>http://t.wits.sg/2009/04/13/howto-controlling-your-presentation-with-your-phone/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 13:41:57 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[quick picks]]></category>
		<category><![CDATA[bluetooth]]></category>
		<category><![CDATA[phone]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=250</guid>
		<description><![CDATA[Yeah i just love seeing the awe on my student&#8217;s faces when i use my phone and my geek geeky geekiest green laser pointer to teach a class. The software is really simple. After trying out Phonepoint and Wireless Presenter (comes preinstalled in my Nokia E66), I&#8217;ve come to pick out Phonepoint as the winner! [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah i just love seeing the awe on my student&#8217;s faces when i use my phone and my geek geeky geekiest <a href="http://www.thinkgeek.com/gadgets/lights/5a47/" target="_blank">green laser pointer</a> to teach a class. The software is really simple. After trying out <a href="http://www.devlex.com/Products/PhonePoint.shtml" target="_blank">Phonepoint</a> and <a href="http://nokia-wireless-presenter.software.informer.com/" target="_blank">Wireless Presenter</a> (comes preinstalled in my Nokia E66), I&#8217;ve come to pick out <a href="http://www.devlex.com/Products/PhonePoint.shtml" target="_blank">Phonepoint</a> as the winner!</p>
<p>Its really simple. Bluetooth connect, open the software on ur PC, open the app on your mobile. Hey ho presto! you&#8217;re ready to go! Try it! its free to try but $19.99 for a license. I&#8217;d say thats worth the money if i get to walk the room looking good.</p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/04/13/howto-controlling-your-presentation-with-your-phone/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 8 &#8211; CRUD &#8211; Update</title>
		<link>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-8-crud-update/</link>
		<comments>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-8-crud-update/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:27:45 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=186</guid>
		<description><![CDATA[Download the source for this entire series here! CRUD &#8211; Update Very similar to the Create phase, this phase basically requires the Form and Form Container blocks, and the controller to save them. Thats all! Repeat the file structure goodness: app/ etc/ modules/ - SavantDegrees_All.xml (Or what ever your company name might be) code/ local/ [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3> CRUD &#8211; Update</h3>
<p>Very similar to the Create phase, this phase basically requires the <code>Form</code> and <code>Form Container</code> blocks, and the <code>controller</code> to save them. Thats all!</p>
<ol>
<li>Repeat the file structure goodness:

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">app/
  etc/
    modules/
      - SavantDegrees_All.xml <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
  code/
    local/
      SavantDegrees/ <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
        Twits/ <span style="color: #33cc33;">(</span>Or whatever your module name might be<span style="color: #33cc33;">)</span>
          Block/
            Admin/
              - Main.php
              Main/
                - Grid.php
              - Edit.php
              Edit/
                - Form.php
              - New.php
              New/
                - Form.php
            - HelloWorld.php
          controllers/
            - AdminController.php
            - IndexController.php
          etc/
            - config.xml
          Helper/
            - Data.php
          Model/
            - Tip.php
            Mysql4/
              - Tip.php
              Tip/
                - Collection.php
          sql/
            twits_setup/
              - mysql4-install-0.2.0.php
              - mysql4-upgrade-0.1.0-0.2.0.php</pre></div></div>

<p>Here we&#8217;ve added the block for the <code>Edit</code> container and <code>Form</code>
</li>
<li>Looking at the <code>Edit.php</code> code:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Admin_Edit <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Form_Container
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twits'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mode <span style="color: #339933;">=</span> <span style="color: #0000ff;">'edit'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_objectId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$tip</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_objectId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frozen_tip'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getHeaderText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Edit Tip'<span style="color: #009933; font-weight: bold;">%s</span>'&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">htmlEscape</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">registry</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frozen_tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The additional code loads the right <code>Tip</code> data based on the <code>Request</code> parameter, then stores that data in the <code>Mage</code> registry. We&#8217;ll be using that data on the <code>Form</code> page again later to populate the form.<br />
Notice that the saving code is <code>Mage::register</code> and the retrieving code is <code>Mage::registry</code>
</li>
<li>Then the accompanying <code>Edit/Form.php</code> code

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Admin_Edit_Form <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Form
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _prepareForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Varien_Data_Form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFieldset</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_tip'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'legend'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip Details'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'maxlength'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'250'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'maxlength'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'250'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contents'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'textarea'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'contents'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contents'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contents'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'style'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'width: 98%; height: 200px;'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 		<span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUseContainer</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAction</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/save'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValues</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">registry</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frozen_tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setForm</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>
Then lastly the <code>adminController</code> with its <code>editAction</code> and <code>saveAction</code> to load and save the form respectively</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_AdminController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Controller_Action
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_main'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tipId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        try <span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSuccess</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip successfully deleted'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_redirectReferer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> newAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_new'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$tip</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            try <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$tip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSuccess</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip successfully saved'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> editAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_edit'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> saveAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tipId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$tip</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            try <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$tip</span> <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSuccess</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip successfully saved'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_redirectReferer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>
Ok i admit the code is a tad inefficient. We have 2 separate functions that both does save. In fact, <code>postAction</code> and <code>saveAction</code> only differ that saveAction loads the right record via the <code>->load($tipId)</code> function. Thats separates a <code>CREATE</code> from an <code>UPDATE</code> request.</p>
<p>And we&#8217;re finally finally finally done! To test out the edit function, simply click on any row from the  <code>Grid</code>! Thats assuming of course that you actually have some data.<br />
<img src="http://t.wits.sg/wp-content/uploads/2009/03/magento_admin_form.jpg" alt="Magento Admin Form" title="Magento Admin Form" style="border: 1px solid #ddd;"  class="size-full wp-image-210" />
</li>
</ol>
<div class="h_l">
<div></div>
</div>
<p>&raquo; For frontend stuff, carry on &#8230; <a href="http://t.wits.sg/2009/06/22/howto-repackageable-custom-extension-development-in-magento-part-9-frontend-list/">Fontend &#8211; List</a></p>
<p>Otherwise, if it works for you, leave a comment! =)</p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-8-crud-update/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 7 &#8211; CRUD &#8211; Create</title>
		<link>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-7-crud-create/</link>
		<comments>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-7-crud-create/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:27:36 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=182</guid>
		<description><![CDATA[Download the source for this entire series here! CRUD &#8211; Create More file structure goodness: 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/ Admin/ - Main.php Main/ - Grid.php - [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3>CRUD &#8211; Create</h3>
<ol>
<li>More file structure goodness:

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">app/
  etc/
    modules/
      - SavantDegrees_All.xml <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
  code/
    local/
      SavantDegrees/ <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
        Twits/ <span style="color: #33cc33;">(</span>Or whatever your module name might be<span style="color: #33cc33;">)</span>
          Block/
            Admin/
              - Main.php
              Main/
                - Grid.php
              - New.php
              New/
                - Form.php
            - HelloWorld.php
          controllers/
            - AdminController.php
            - IndexController.php
          etc/
            - config.xml
          Helper/
            - Data.php
          Model/
            - Tip.php
            Mysql4/
              - Tip.php
              Tip/
                - Collection.php
          sql/
            twits_setup/
              - mysql4-install-0.2.0.php
              - mysql4-upgrade-0.1.0-0.2.0.php</pre></div></div>

<p>Here we&#8217;ve added the block for the <code>New</code> container and <code>Form</code>
</li>
<li>Looking at the <code>New.php</code> code:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Admin_New <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Form_Container
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twits'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mode <span style="color: #339933;">=</span> <span style="color: #0000ff;">'new'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getHeaderText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add New Tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Then the <code>New/Form.php</code> code

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Admin_New_Form <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Form
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _prepareForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Varien_Data_Form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFieldset</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'new_tip'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'legend'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip Details'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'maxlength'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'250'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'maxlength'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'250'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contents'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'textarea'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'contents'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contents'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contents'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'style'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'width: 98%; height: 200px;'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUseContainer</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAction</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/post'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setForm</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Just like your listings/grid page, the <code>New.php</code> and <code>Form.php</code> classes are the <code>Form Container</code> and <code>Form</code> respectively. So the <code>Form Container</code> automagically creates the form. Did I mention why containers are good? They come with nice pretty buttons! (Save and Back).
</li>
<li>
Then lastly the <code>adminController</code> with its <code>newAction</code> and <code>postAction</code> to load and save the form respectively</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_AdminController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Controller_Action
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_main'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tipId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        try <span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSuccess</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip successfully deleted'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_redirectReferer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> newAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_new'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$tip</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            try <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$tip</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSuccess</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip was successfully saved'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>
Reward yourself for your lightning fast copy-and-paste kung foo! Whats happening though?<br />
When the script receives a  call <code>newAction</code>, it&#8217;ll show the form to enter data. The data is posted to the <code>postAction</code> method. That method creates an instance of the model, sets the post data into the model, saves it then redirects it back to the <code>indexAction</code>. Did i mention automagically? Yes, thats why we had to learn so much of the Magento code just to write this simple tutorial.   The sql is automagically generated and run and the form is automagically created! *sheds a tear*</p>
<p>Again, your well deserved create form can be found by clicking on the &#8220;Add New Tip&#8221; button from the <code>Grid</code>!
</li>
</ol>
<div class="h_l">
<div></div>
</div>
<p>&raquo; Just 1 more &#8230; <a href="http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-8-crud-update/">CRUD &#8211; Update</a></p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-7-crud-create/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 6 &#8211; CRUD &#8211; Delete</title>
		<link>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-6-crud-delete/</link>
		<comments>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-6-crud-delete/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:22:25 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=178</guid>
		<description><![CDATA[Download the source for this entire series here! CRUD &#8211; Delete The simplest step thus far, add a new function to your AdminController.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 &#60;?php class SavantDegrees_Twits_AdminController extends Mage_Adminhtml_Controller_Action [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3>CRUD &#8211; Delete</h3>
<ol>
<li>The simplest step thus far, add a new function to your <code>AdminController.php</code>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_AdminController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Controller_Action
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_main'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$tipId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        try <span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tipId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addSuccess</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tip successfully deleted'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_redirectReferer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
</ol>
<div class="h_l">
<div></div>
</div>
<p>&raquo; Almost there &#8230; <a href="http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-7-crud-create/">CRUD &#8211; Create</a></p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-6-crud-delete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 5 &#8211; CRUD &#8211; Retrieve</title>
		<link>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-5-crud-retrieve/</link>
		<comments>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-5-crud-retrieve/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:18:54 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=173</guid>
		<description><![CDATA[Download the source for this entire series here! CRUD &#8211; Retrieve Lets add a new block to the file structure 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/ Admin/ - [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3>CRUD &#8211; Retrieve</h3>
<ol>
<li>Lets add a new block to the file structure

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">app/
  etc/
    modules/
      - SavantDegrees_All.xml <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
  code/
    local/
      SavantDegrees/ <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
        Twits/ <span style="color: #33cc33;">(</span>Or whatever your module name might be<span style="color: #33cc33;">)</span>
          Block/
            Admin/
              - Main.php
              Main/
                - Grid.php
            - HelloWorld.php
          controllers/
            - AdminController.php
            - IndexController.php
          etc/
            - config.xml
          Helper/
            - Data.php
          Model/
            - Tip.php
            Mysql4/
              - Tip.php
              Tip/
                - Collection.php
          sql/
            twits_setup/
              - mysql4-install-0.2.0.php
              - mysql4-upgrade-0.1.0-0.2.0.php</pre></div></div>

<p>We&#8217;ll create folder called <code>Admin</code> to store all the admin related blocks. Inside we&#8217;ll have a Main.php file that contains the <code>Grid Container</code>. Why do we need a grid container? To put the title and <code>Create</code> button!
</li>
<li>
The <code>Main.php</code> code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Admin_Main <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid_Container
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButtonLabel <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add New Tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twits'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin_main'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headerText <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tips(s)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here you see a first use of the helper, which will assist in translation
</li>
<li>
The <code>Grid.php</code> itself</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Block_Admin_Main_Grid <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tipsGrid'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'twits'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _prepareCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$collection</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCollection</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$collection</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span>_prepareCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _prepareColumns<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tip_id'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'header'</span>        <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'align'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'right'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'width'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'50px'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'filter_index'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dt.tip_id'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'index'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tip_id'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'header'</span>        <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'align'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'left'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'width'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'150px'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'filter_index'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dt.title'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'index'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'type'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'truncate'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'escape'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tags'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'header'</span>    	<span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'align'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'left'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'filter_index'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dt.author'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'index'</span>    	 	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'type'</span>     	 	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'escape'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'summary'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'header'</span>        <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contents'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'align'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'left'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'filter_index'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dt.contents'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'index'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'contents'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'type'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'escape'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'header'</span>    <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'width'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'150px'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'type'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'action'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'getter'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'getTipId'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'actions'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'caption'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Edit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'url'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                            <span style="color: #0000ff;">'base'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'*/*/edit'</span>
                         <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                         <span style="color: #0000ff;">'field'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'caption'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Delete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'url'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                            <span style="color: #0000ff;">'base'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'*/*/delete'</span>
                         <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                         <span style="color: #0000ff;">'field'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span>
                    <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'filter'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'sortable'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span>_prepareColumns<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRowUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*/*/edit'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTipId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you scrutinize the code (which i&#8217;d advise against), you&#8217;ll see most of the code is geared towards the setup of the grid columns and the edit/delete urls i&#8217;ll eventually call to perform the other <code>CRUD</code> functions.<br />
But whats going on? Where do we use this code? The main code (being a <code>Grid_Container</code> automatically adds the child <code>Grid</code> code associated to it. By child we&#8217;re talking about the <code>Grid.php</code> file in the <code>Main</code> folder. The folder&#8217;s name follows the file. So if you changed the folder&#8217;s name to <code>Main2</code>, it wouldnt work. That being said, you can just put any block code in the folder and expect it to run. The reason why this all works now is cause the geniuses at Magento already did alot of work to call the Grid child to run. They have no super time travel powers to tell what else you&#8217;re gonna put in there. So, it simply wont work (yet).
</li>
<li>Now lets make our <code>adminController.php</code> use that block instead of Hello world.

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_AdminController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Controller_Action
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span>_addContent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/admin_main'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Well it says <code>createBlock</code> doesnt it? What do you think it does? <code>twits/admin_main</code> as always refers to the twits namespace and the <code>admin/main.php</code> block file.
</li>
<li>Viola! Your very very very hard earned grid!<br />
<img src="http://t.wits.sg/wp-content/uploads/2009/03/magento_admin_grid.jpg" alt="Magento Admin Grid" title="Magento Admin Grid" style="border: 1px solid #ddd;" class="size-full wp-image-204" />
</li>
</ol>
<div class="h_l">
<div></div>
</div>
<p>&raquo; Anytime now &#8230; <a href="http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-6-crud-delete/">Part 6 &#8211; CRUD &#8211; Delete</a></p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-5-crud-retrieve/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 4 &#8211; Model</title>
		<link>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-4-model/</link>
		<comments>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-4-model/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:14:39 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=167</guid>
		<description><![CDATA[Download the source for this entire series here! Prepare the model Back to the file structure drawing board 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/ - [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3>Prepare the model</h3>
<ol>
<li>Back to the file structure drawing board

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">app/
  etc/
    modules/
      - SavantDegrees_All.xml <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
  code/
    local/
      SavantDegrees/ <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
        Twits/ <span style="color: #33cc33;">(</span>Or whatever your module name might be<span style="color: #33cc33;">)</span>
          Block/
            - HelloWorld.php
          controllers/
            - AdminController.php
            - IndexController.php
          etc/
            - config.xml
          Helper/
            - Data.php
          Model/
            - Tip.php
            Mysql4/
              - Tip.php
              Tip/
                - Collection.php
          sql/
            Twits_setup/
              - mysql4-install-0.2.0.php
              - mysql4-upgrade-0.1.0-0.2.0.php</pre></div></div>

<p>Notice the new folder <code>Model</code> and the associated files inside. Lets clarify:<br />
<code>Model/Tip.php</code> is the logical model that holds code regarding business logic and relations.<br />
<code>Model/Mysql4/Tip.php</code> is the data implementation model that associates the model with the table and its primary key.<br />
<code>Model/Mysql4/Tip/Collection.php</code> is the data implementation model of a collection of <code>Tip</code>. Similar to a <code>recordset/resultset</code> in <code>.Net/Java</code>. This will be used with a Grid later.</li>
<li>Even more <code>config.xml</code> magic. Yay! More hairloss!

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.2.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resourceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>twits_mysql4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resourceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_mysql4<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits_Model_Mysql4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tips<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_mysql4<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;blocks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits_Block<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/blocks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;helpers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits_Helper<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/helpers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_write<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_read<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;title&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;twits&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>twits/admin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>standard<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The <code>global > models</code> fragment define the <code>tips</code> table, the <code>tip model</code> and its <code>resourceModel</code> that we will be using shortly.</li>
<li>Now for the <code>model/Tip.php</code> code:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Model_Tip <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Abstract
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Whats the point you ask!? The code does nothing but binds the model to the Twits namespace under the model twits. In Java that line would have been <code>package Twits;</code>. *i assume/think/foretold*<br />
(quickly moving on&#8230;)</li>
<li> Then <code>Model/Mysql4/Tip.php</code>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Model_Mysql4_Tip <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Mysql4_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tip_id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code above tells Magento to hunt for the twits application&#8217;s twits table in the configuration. Yes i know the names are confusing now. Lets say instead of <code>twits/tip</code> it is <code>twits/foo</code>. In that case the system will find the configuration file associated with twits (which is our app/code/local/SavantDegrees/Twits/etc/config.xml), and look under <code>config > global > models > twits_mysql4 > entities > foo </code> to figure out its configuration instructions. You&#8217;ll see next that we&#8217;ll request for the table from that same configuration file. Capiche?<br />
As a <code>resourceModel</code>, the code binds the model to a underlying <code>Mysql4 table</code>. </li>
<li> Lastly, <code>Model/Mysql4/Tip/Collection.php</code>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> SavantDegrees_Twits_Model_Mysql4_Tip_Collection <span style="color: #000000; font-weight: bold;">extends</span> Varien_Data_Collection_Db
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_tipTable</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$resources</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/resource'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits_read'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_tipTable<span style="color: #339933;">=</span> <span style="color: #000088;">$resources</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTableName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_select<span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span>
        		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tip'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_tipTable<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
 		       	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*'</span><span style="color: #009900;">&#41;</span>
        		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setItemObjectClass</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">getConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModelClassName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twits/tip'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Basically the model files created at this phase are simply trying to tie the model (singular and collection) to the underlying <code>Mysql resource</code>. The entire mechanism is half tied in the <code>config.xml</code> table declaration, the model individual instructions (from identifying the namespace to actually declaring the primary key of the table)</li>
<li>Viola. Models are ready</li>
</ol>
<div class="h_l">
<div></div>
</div>
<p>&raquo; Arent we there yet? <a href="http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-5-crud-retrieve/">Part 5 &#8211; CRUD &#8211; Retrieve</a></div>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-4-model/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Howto: Repackageable custom extension development in Magento &#8211; Part 3 &#8211; Database</title>
		<link>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-3-database/</link>
		<comments>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-3-database/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 08:12:18 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=164</guid>
		<description><![CDATA[Download the source for this entire series here! Prepare the database Next we&#8217;ll create the installation script that installs the twits table into the database. Once again, we begin with updating the file structure app/ etc/ modules/ - SavantDegrees_All.xml (Or what ever your company name might be) code/ local/ SavantDegrees/ (Or what ever your company [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloads/magento-tutorial.zip"><img src="http://t.wits.sg/wp-content/uploads/2009/03/download.png" alt="" title="download Magento Tutorial" /></a></h4>
</div>
<div class="h_l">
<div></div>
</div>
<h3>Prepare the database</h3>
<p>Next we&#8217;ll create the installation script that installs the twits table into the database.</p>
<ol>
<li>Once again, we begin with updating the file structure

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">app/
  etc/
    modules/
      - SavantDegrees_All.xml <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
  code/
    local/
      SavantDegrees/ <span style="color: #33cc33;">(</span>Or what ever your company name might be<span style="color: #33cc33;">)</span>
        Twits/ <span style="color: #33cc33;">(</span>Or whatever your module name might be<span style="color: #33cc33;">)</span>
          Block/
            - HelloWorld.php
          controllers/
            - AdminController.php
            - IndexController.php
          etc/
            - config.xml
          Helper/
            - Data.php
          sql/
            twits_setup/
              - mysql4-install-0.2.0.php
              - mysql4-upgrade-0.1.0-0.2.0.php</pre></div></div>

<p>We simply included a <code>sql</code> folder that will house the eventual table creation sql code.</li>
<li>Next up, updating the <code>config.xml</code> again. This time to add the setup declarations.

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.2.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;blocks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits_Block<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/blocks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;helpers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits_Helper<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/helpers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_write<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_read<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;twits</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;title&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;twits&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>100<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>twits/admin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/menu<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adminhtml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>standard<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>SavantDegrees_Twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>twits<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/args<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SavantDegrees_Twits<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/routers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Here we&#8217;ve added a <code>global > resources</code> section that tells the setup script the folder for installation. We&#8217;ve also changed the version number to <code>0.2.0</code>. When the page is initiated and Magento detects that the version has been upgraded, it will run the appropriate install script.</li>
<li> Lastly the install script itself: <code>mysql4-install-0.2.0.php</code>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$installer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
CREATE TABLE {<span style="color: #006699; font-weight: bold;">$this-&gt;getTable</span>('tips')} (
  `tip_id` int(10) unsigned NOT NULL auto_increment,
  `title` varchar(250) NOT NULL default '',
  `author` varchar(250) default NULL,
  `contents` text,
  PRIMARY KEY  (`tip_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Copy the same file contents to <code>mysql4-upgrade-0.1.0-0.2.0.php</code>. Why? because the code above is correct. But since this HOWTO is going through the phases in version 0.1, 0.2, and etc. Magento has already a record of <code>twit_setup</code> in its <code>core_resource</code> table bound to the previous version of 0.1 (its first run). So what we need now is a upgrading script instead of an installer. But if/when you do package your extension, you shouldn&#8217;t need the upgrade code. Just install straight to version 0.2 (or higher)</li>
<li>Once again, wake up the Magento installer by logging into the <code>admin</code> backend, <code>System > Configuration > Advanced</code>. Click on <code>Save Config</code>. Clear your cache at <code>/var/cache</code> too just to be sure.</li>
<li>Check to see if your table is created.</li>
<li>Once your table is created, you can delete the <code>mysql4-upgrade-0.1.0-0.2.0.php</code> file. As explained above, you dont need it anymore!</li>
</ol>
<div class="h_l">
<div></div>
</div>
<p>&raquo; More Intangibles! &#8230; <a href="http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-4-model/">Part 4 &#8211; Model</a></p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2009/03/31/howto-repackageable-custom-extension-development-in-magento-part-3-database/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

