<?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>Aviblock.com &#187; Zend_Form</title>
	<atom:link href="http://www.aviblock.com/blog/tag/zend_form/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aviblock.com/blog</link>
	<description>My musings on web development</description>
	<lastBuildDate>Thu, 03 Jun 2010 13:40:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Alternative to Zend_Form ViewScript decorator</title>
		<link>http://www.aviblock.com/blog/2009/11/29/alternative-to-zend_form-viewscript-decorator/</link>
		<comments>http://www.aviblock.com/blog/2009/11/29/alternative-to-zend_form-viewscript-decorator/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 16:34:04 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ViewScript decorator]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Form]]></category>

		<guid isPermaLink="false">http://www.aviblock.com/blog/?p=79</guid>
		<description><![CDATA[Zend_Form is great for prototyping forms. It takes a lot of the drudge work out, and makes forms easily &#8220;reusable&#8221;. The decorator system, which is admittedly a little scary for the uninitiated, is actually very powerful. I&#8217;m suer that eventually, however, we&#8217;ve all reached that point. The point where you spend more time configuring the [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Form is great for prototyping forms. It takes a lot of the drudge work out, and makes forms easily &#8220;reusable&#8221;. The decorator system, which is admittedly a little scary for the uninitiated, is actually very powerful. I&#8217;m suer that eventually, however, we&#8217;ve all reached that point. The point where you spend more time configuring the form to do what you want, then actually doing something with it.<span id="more-79"></span><br />
This is especially more important when working with talented designers who know their HTML/CSS, and know exactly what theywant to do with the form. Trying to mangle the form to do what they want in that case is generally a waste of time. It also makes it much harder for the designer to apply his CSS magic. You might look and smile at how beautiful <?=$this->form?> looks, abstracting away all you hard work. However the designer will likely have to see the generated html to get an understanding of the structure. Want to add a CSS class? Good luck.<br />
Eventually, we discover the ViewScript decorator. Although the code in that viewscript can be a bit complex, we once again have panacea. The designer gets a viewscript with which he can muck around. You get to set one or two decorators and we&#8217;re back to <?=$this->form?> again.<br />
How does the ViewScript decorator work? The workhorse of it involves setting up a partial, and pushing in to the &#8220;model&#8221; of the partial, the form under the alias &#8220;element&#8221;. Now, anybody who&#8217;s read the Zend Framework performance guide, will have noticed that use of partials is somewhat discouraged. To create a partial, it involves cloning Zend_View, and is somewhat of an unneeded overhead.<br />
So is there an an alternative? It hit me today, that there&#8217;s absolutely nothing wrong with just outputting the form in the viewscript it self. Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderViewHelper</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/form&gt;</pre></div></div>

<p>In a form ViewScript, just output that directly into your viewscript!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderViewHelper</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/form&gt;</pre></div></div>

<p>If you want the script to be reusable, just use the render viewhelper, as recommended in the performance guide.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.aviblock.com/blog/2009/11/29/alternative-to-zend_form-viewscript-decorator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
