<?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; db</title>
	<atom:link href="http://t.wits.sg/tag/db/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>Mon, 14 Jun 2010 01:55:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</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/downloadsmagento-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: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
  code/
    local/
      SavantDegrees/ <span style="color: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
        Twits/ <span style="color: #66cc66;">&#40;</span>Or whatever your module name might be<span style="color: #66cc66;">&#41;</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>8</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 &#40;Or what ever your company name might be&#41; code/ local/ [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloadsmagento-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: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
  code/
    local/
      SavantDegrees/ <span style="color: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
        Twits/ <span style="color: #66cc66;">&#40;</span>Or whatever your module name might be<span style="color: #66cc66;">&#41;</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>
	protected <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>16</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 &#40;Or what ever your company name might be&#41; code/ local/ SavantDegrees/ &#40;Or what ever your company name might be&#41; Twits/ &#40;Or whatever your module name might be&#41; 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/downloadsmagento-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: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
  code/
    local/
      SavantDegrees/ <span style="color: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
        Twits/ <span style="color: #66cc66;">&#40;</span>Or whatever your module name might be<span style="color: #66cc66;">&#41;</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>
    protected <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>4</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/downloadsmagento-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 &#40;Or what ever your company name might be&#41; code/ local/ SavantDegrees/ &#40;Or what ever your company name might be&#41; Twits/ &#40;Or whatever your module name might be&#41; Block/ Admin/ - [...]]]></description>
			<content:encoded><![CDATA[<div class="contentblock">
<h4>Download the source for this entire series here! <a href="http://t.wits.sg/downloadsmagento-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: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
  code/
    local/
      SavantDegrees/ <span style="color: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
        Twits/ <span style="color: #66cc66;">&#40;</span>Or whatever your module name might be<span style="color: #66cc66;">&#41;</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;
    protected <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;
    protected <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>7</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 &#40;Or what ever your company name might be&#41; code/ local/ SavantDegrees/ &#40;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/downloadsmagento-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: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
  code/
    local/
      SavantDegrees/ <span style="color: #66cc66;">&#40;</span>Or what ever your company name might be<span style="color: #66cc66;">&#41;</span>
        Twits/ <span style="color: #66cc66;">&#40;</span>Or whatever your module name might be<span style="color: #66cc66;">&#41;</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>
		<item>
		<title>HOWTO: Scheduled Remote MySQL Backups</title>
		<link>http://t.wits.sg/2008/06/18/howto-scheduled-remote-mysql-backups/</link>
		<comments>http://t.wits.sg/2008/06/18/howto-scheduled-remote-mysql-backups/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 08:30:43 +0000</pubDate>
		<dc:creator>gaweee</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[db]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=13</guid>
		<description><![CDATA[If you have more access to more than 1 server, a good idea would be to schedule remote backups using a small script and crontab. This way, if 1 server goes down at least SOME data still resides on another. (a friend&#8217;s hosting service got prematurely terminted recently because someone else sharing a hosting plan [...]]]></description>
			<content:encoded><![CDATA[<p>If you have more access to more than 1 server, a good idea would be to schedule remote backups using a small script and crontab. This way, if 1 server goes down at least SOME data still resides on another. (a friend&#8217;s hosting service got prematurely terminted recently because someone else sharing a hosting plan was serving illegal content and the whole system was confiscated by the police in that country!)</p>
<p>of course backing up mysql is the only thing you can do, unless you&#8217;ve way too much disk space and way too much bandwidth&#8230; in that case please consult a professional on the actual 1001 ways to throw money at redundancy.</p>
<p>The script will first run remote commands on the target server over ssh to dump and gzip the database into a file. The file is then downloaded to the backup server. A final ssh command removes the dump file from the target server. Viola! And here is the shell script&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">ssh root@wits.sg 'mysqldump -uroot twits&gt; /tmp/twits.backup.sql &amp;&amp; bzip2 -9 /tmp/twits.backup.sql'
scp root@wits.sg:/tmp/twits.backup.sql.bz2 /var/backups/twits/`date &quot;+%Y%m%d-%H%M&quot;`.sql.bz2
ssh root@wits.sg 'rm /tmp/twits.backup.sql.bz2'</pre></div></div>

<p>Save this few lines to a file on the backup server and give it execute permissions! (I saved it at /root/twits_backup.sh)<br />
<strong>Note:</strong> <a href="http://t.wits.sg/2008/06/15/howto-passwordless-logins-between-servers/">Passwordless logins between the 2 servers</a> must have been setup prior to running this script. Otherwise scp and ssh commands will both be prompted for a password.</p>
<p>Next set up the cron job on the backup server to run the script</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">30 05 * * * /root/twits_backup.sh</pre></div></div>

<p>This sets the script to run at 5:30am everyday.<br />
<a href="http://crunchbang.org/archives/2007/10/26/howto-setup-a-crontab-file/">Here</a> is a good place to read up more on cron jobs.</p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2008/06/18/howto-scheduled-remote-mysql-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO: Did you mean&#8230;</title>
		<link>http://t.wits.sg/2008/06/17/howto-did-you-mean/</link>
		<comments>http://t.wits.sg/2008/06/17/howto-did-you-mean/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 07:38:42 +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[levenshtein]]></category>
		<category><![CDATA[metaphone]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[soundex]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://t.wits.sg/?p=12</guid>
		<description><![CDATA[I always thought it was really cool to have those &#8220;Did you mean &#60;some other spelling corrected word&#62;&#8221;? Took me long enough to finally chance upon how it works! Basically it uses sound functions: soundex, metaphone or levenshtein distance to match words. Different database supports different possible implementations of the functions. A sample mySQL query [...]]]></description>
			<content:encoded><![CDATA[<p>I always thought it was really cool to have those &#8220;Did you mean &lt;some other spelling corrected word&gt;&#8221;? Took me long enough to finally chance upon how it works! Basically it uses sound functions: <a href="http://us2.php.net/manual/en/function.soundex.php" target="_blank">soundex</a>, <a href="http://us2.php.net/manual/en/function.metaphone.php" target="_blank">metaphone</a> or <a href="http://us2.php.net/manual/en/function.levenshtein.php" target="_blank">levenshtein distance</a> to match words.</p>
<p>Different database supports different possible implementations of the functions. A sample mySQL query would look like:</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">SELECT `name` FROM `organizations` WHERE SOUNDEX(`name`) = SOUNDEX('dog');</pre></div></div>

<p>I&#8217;ve also seen some mysql stored procs that hack in a levenshtein distance calculation algorithm. This allows a even more dynamic and accurate match. Unfortunately, i&#8217;ve never gotten it to work. Do let me know if anyone has succeeded.</p>
]]></content:encoded>
			<wfw:commentRss>http://t.wits.sg/2008/06/17/howto-did-you-mean/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
