<?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>Andrew Vayanis &#187; Zend Framework</title>
	<atom:link href="http://www.vayanis.com/category/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vayanis.com</link>
	<description>Developer, Gamer, Thinker</description>
	<lastBuildDate>Wed, 19 May 2010 15:58:46 +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>Intro to Zend Framework Routing</title>
		<link>http://www.vayanis.com/2009/03/20/intro-to-zend-framework-routing/</link>
		<comments>http://www.vayanis.com/2009/03/20/intro-to-zend-framework-routing/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 14:56:28 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/?p=32</guid>
		<description><![CDATA[Edit: I originally started working on this article several months ago, however, as I was editing it, the Zend Framework team released a revamped reference guide that goes through much of what I discuss.  Hopefully though, this still ends up being useful and informative for someone out there.
Edit #2: I don&#8217;t mean for this [...]]]></description>
			<content:encoded><![CDATA[<p>Edit: I originally started working on this article several months ago, however, as I was editing it, the Zend Framework team released a revamped reference guide that goes through much of what I discuss.  Hopefully though, this still ends up being useful and informative for someone out there.</p>
<p>Edit #2: I don&#8217;t mean for this article to be followed verbatim, but rather, used as a guide to understanding Zend Framework&#8217;s routing process.  </p>
<p>Now that I am using ZF for current projects at work, I have taken the opportunity to promote ZF with my colleagues.  One colleague in particular, who has been using <a href="http://www.codeigniter.com">Code Igniter</a>(CI), was somewhat perplexed by ZF&#8217;s seeming complexity, even after reading through the first few sections of the <a href="http://framework.zend.com/manual/en/">Reference Guide</a>.  In particular, he didn&#8217;t understand how ZF handled URIs as it is quite different from CI.  So, I have put together the following, hopefully simple overview, explaining a bit about ZF&#8217;s routing and using it in conjunction with Zend_Config.<br />
<span id="more-32"></span><br />
Out of the box, ZF routes URIs by turning the first segment into the controller and the second segment into the action, unless you have specified a module directory, in which case, the first segment becomes the module, the second segment the controller and the third segment the action.  Any segments beyond that are converted into key-value pairs that are accessible through the front controller&#8217;s request object.</p>
<p>Therefore, something like http://www.vayanis.com/post/view/id/101/title/new-post is translated into a request for the &#8216;post&#8217; controller, and &#8216;view&#8217; action with two request parameters: &#8216;id&#8217; with value &#8216;101&#8242; and &#8216;title with value &#8216;new-post&#8217;.  Accessing these parameters is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_request<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Unfortunately, this default behavior is bad for SEO because it adds unnecessary and useless information to the URI, but like many things in ZF, there is a solution and so I turn to the <a href="http://framework.zend.com/manual/en/zend.controller.router.html">Zend_Controller_Router_Rewrite</a>.<br />
As the documentation states:</p>
<blockquote><p>Zend_Controller_Router_Rewrite is designed to allow for mod_rewrite-like functionality using pure php structures. It is very loosely based on Ruby on Rails routing and does not require any prior knowledge of webserver URL rewriting.</p></blockquote>
<p>So, to simplify this URI, I can create the following route:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get Front Controller Instance</span>
<span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get Router</span>
<span style="color: #000088;">$router</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Router_Route<span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'post/:id/:title'</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'blog'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'action'</span>     <span style="color: #339933;">=&gt;</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;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addRoute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$route</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will shorten the previous, lengthy URI from http://www.vayanis.com/post/view/id/101/title/new-post to http://www.vayanis.com/view/101/new-post</p>
<p>Finally, like most components, if you are not comfortable maintaining your configuration in pure php, you can instead use a INI config file.  The equivalent of the previous example could be defined in an INI config file with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>production<span style="">&#93;</span></span>
routes.post.route <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;post/:id/:title&quot;</span>
routes.post.defaults.controller <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> blog</span>
routes.post.defaults.action <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> post</span></pre></div></div>

<p>To use the INI with a router, use the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get Front Controller Instance</span>
<span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get Router</span>
<span style="color: #000088;">$router</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRouter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$router</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addConfig</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path/to/route/config/file'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'production'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'routes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2009/03/20/intro-to-zend-framework-routing/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating Tables with Zend_Form</title>
		<link>http://www.vayanis.com/2008/03/26/creating-tables-with-zend_form/</link>
		<comments>http://www.vayanis.com/2008/03/26/creating-tables-with-zend_form/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 05:47:17 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Tables]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Framework]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/2008/03/26/creating-tables-with-zend_form/</guid>
		<description><![CDATA[I recently published an article trying to shed some light on the Zend_Form component, in particular, when using it with Zend_Config_Ini.  In the article I presented a config I developed while trying to learn Zend_Form myself, but unfortunately realized that using generic elementDecorators comes with a price.

Apparently, using elementDecorators overrides individual element level decorators. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently published an <a href="http://www.vayanis.com/2008/03/17/using-zend_form-with-zend_config/">article</a> trying to shed some light on the <a href="http://framework.zend.com/manual/en/zend.form.html">Zend_Form</a> component, in particular, when using it with Zend_Config_Ini.  In the article I presented a config I developed while trying to learn Zend_Form myself, but unfortunately realized that using generic <em>elementDecorators</em> comes with a price.<br />
<span id="more-29"></span><br />
Apparently, using elementDecorators overrides individual element level decorators.  This leads to some unexpected and annoying results.  For instance, in my previous example, I lose the ability to hide or even add individual attributes to specific elements.  This leaves me with a form that has labels for each element including the submit button:<br />
<img src='http://www.vayanis.com/wp-content/uploads/2008/03/zend_form-table-login-1.png' alt='Zend Form Table Login with all Labels' /></p>
<p>The only way I found to correct this problem is to add decorators to each element individually.  This is highly redundant and hardly ideal, but it gives the control necessary to fix this problem.  It also bloats the config file significantly; previously, the config was 31 lines long, but now it is 47 lines long:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>login<span style="">&#93;</span></span>
<span style="color: #666666; font-style: italic;">; General Form Information</span>
login.action <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;login/submit&quot;</span>
login.method <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;post&quot;</span>
login.id <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;login&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Form Decorators</span>
login.decorators.elements.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;FormElements&quot;</span>
login.decorators.table.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.decorators.table.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;table&quot;</span>
login.decorators.form.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Form&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Username Element</span>
login.elements.username.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;text&quot;</span>
login.elements.username.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Username:&quot;</span>
login.elements.username.options.required <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
login.elements.username.options.validators.alnum.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;alnum&quot;</span>
login.elements.username.options.validators.regex.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;regex&quot;</span>
login.elements.username.options.validators.regex.options.pattern <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;/^[a-z]/i&quot;</span>
login.elements.username.options.validators.strlen.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;StringLength&quot;</span>
login.elements.username.options.validators.strlen.options.min <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;5&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Username Decorators</span>
login.elements.username.options.decorators.helper <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;ViewHelper&quot;</span>
login.elements.username.options.decorators.tableData.decorator.td <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.elements.username.options.decorators.tableData.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
login.elements.username.options.decorators.label.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Label&quot;</span>
login.elements.username.options.decorators.label.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
login.elements.username.options.decorators.tableRow.decorator.tr <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.elements.username.options.decorators.tableRow.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;tr&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Password Element</span>
login.elements.password.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;password&quot;</span>
login.elements.password.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Password:&quot;</span>
login.elements.password.options.required <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
login.elements.password.options.validators.strlen.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;StringLength&quot;</span>
login.elements.password.options.validators.strlen.options.min <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;6&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Password Decorators</span>
login.elements.password.options.decorators.helper <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;ViewHelper&quot;</span>
login.elements.password.options.decorators.tableData.decorator.td <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.elements.password.options.decorators.tableData.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
login.elements.password.options.decorators.label.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Label&quot;</span>
login.elements.password.options.decorators.label.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
login.elements.password.options.decorators.tableRow.decorator.tr <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.elements.password.options.decorators.tableRow.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;tr&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Submit Form Element</span>
login.elements.submit.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;submit&quot;</span>
login.elements.submit.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Submit&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Submit Decorators</span>
login.elements.submit.options.decorators.helper <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;ViewHelper&quot;</span>
login.elements.submit.options.decorators.tableData.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.elements.submit.options.decorators.tableData.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
login.elements.submit.options.decorators.label.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Label&quot;</span>
login.elements.submit.options.decorators.label.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
login.elements.submit.options.decorators.label.options.class <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;submit&quot;</span>
login.elements.submit.options.decorators.tableRow.decorator.tr <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
login.elements.submit.options.decorators.tableRow.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;tr&quot;</span></pre></div></div>

<p>Personally, I think this is poor design and feel it may even be a bug, but I will attempt to submit it to ZF&#8217;s issue tracker and see what they say.  Otherwise though, I still feel as though Zend_Form is a great component, and will continue to publish any discoveries I come across.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2008/03/26/creating-tables-with-zend_form/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Using Zend_Form with Zend_Config</title>
		<link>http://www.vayanis.com/2008/03/17/using-zend_form-with-zend_config/</link>
		<comments>http://www.vayanis.com/2008/03/17/using-zend_form-with-zend_config/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 05:35:41 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Guides]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Form Tables]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/2008/03/17/using-zend_form-with-zend_config/</guid>
		<description><![CDATA[In my previous post Zend Framework, A First Look, I discussed the lacking nature of ZF&#8217;s documentation, in particular, with regards to Zend_Form.  I have since then learned that this is partly due to the fact that Zend_Form is a relatively new component.  However, I   still wanted to make use of [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post <a href="http://www.vayanis.com/2008/03/14/zend-framework-a-first-look/">Zend Framework, A First Look</a>, I discussed the lacking nature of ZF&#8217;s documentation, in particular, with regards to Zend_Form.  I have since then learned that this is partly due to the fact that Zend_Form is a relatively new component.  However, I   still wanted to make use of Zend_Form in my current project and decided to trudge through the learning curve of creating a simple custom login form in conjunction with Zend_Config; the end result being an easy to maintain, custom form and this guide.  Hopefully, this guide will make it easier for anyone else looking to take advantage of this very cool feature.<br />
<span id="more-28"></span><br />
Before I begin talking about how Zend_Form works, I think it is important to explain a bit about Zend_Config and how an INI file is translated into PHP.  As the <a href="http://framework.zend.com/manual/en/zend.config.html">Zend_Config Documentation</a> points out, it makes use of PHP native parse_ini_file, however, this only goes so far as reading in the contents of the file and turning it into a 1 dimensional associative array(2 if a section is provided).  Zend_Config extends this behavior by taking the keys of each association and breaking them down further based upon the specified <em>key separator (default is &#8216;.&#8217;).</em> and turning the remainder into arrays.  In the end, Zend_Config takes a series of declarations such as the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">login.elements.username.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;text&quot;</span></pre></div></div>

<p>And turns it into:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span>login<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>elements<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                <span style="color: #009900;">&#40;</span>
                    <span style="color: #009900;">&#91;</span>username<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
                        <span style="color: #009900;">&#40;</span>
                            <span style="color: #009900;">&#91;</span>type<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> text
                        <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Now, back to Zend_Form.  I think my biggest gripe with the documentation provided for Zend_Form is that it does not explain how anything is working behind the scenes.  For instance, it does not explain that Zend_Form normalizes config statements by prepending &#8217;set&#8217; when making calls to member methods.  This is invaluable as it explains why</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setElementDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ViewHelper'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>in PHP becomes</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">    elementDecorators.helper <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;ViewHelper&quot;</span></pre></div></div>

<p>in a Zend_Config_Ini.  Internally, elementDecorators tells Zend_Form to call setElementDecorators();  This small example also shows why it is important to know how Zend_Config_Ini actually translates an INI to PHP&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span>elementDecorators<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>helper<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> ViewHelper
        <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>As we can see this declares an array of decorators to be passed into setElementDecorators();  The keys, in this case &#8220;helper&#8221;, do not necessarily matter as it is only needed to index the array, the values are what matter, as that is what is passed and used within Zend_Form.  Similarly, it is important to know that almost all aspects of form and form elements, excluding form element type, are implemented internally as options.  The following is an example INI file with comments explaining particular sections.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">; A basic Form config</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; First level attributes are automatically treated as options.</span>
    <span style="color: #000099;">action</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;login/submit&quot;</span>
    <span style="color: #000099;">method</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;post&quot;</span>
    <span style="color: #000099;">id</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;login&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Form Decorators</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Again these decorators are treated as options of the main form.</span>
    decorators.elements.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;FormElements&quot;</span>
    decorators.table.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
    decorators.table.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;table&quot;</span>
    decorators.form.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Form&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Username Element</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Form Element Type is specified explicityly, not as an option.</span>
    elements.username.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;text&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Username attributes (Label, Required, and validators are all</span>
    <span style="color: #666666; font-style: italic;">; declared as options).</span>
    elements.username.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Username:&quot;</span>
    elements.username.options.required <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
    elements.username.options.validators.alnum.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;alnum&quot;</span>
    elements.username.options.validators.regex.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;regex&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Validator parameters such as pattern to regex are also</span>
    <span style="color: #666666; font-style: italic;">; declared as options. I have not looked into it, but I</span>
    <span style="color: #666666; font-style: italic;">; assume this is due to the way Zend_Validate handles its</span>
    <span style="color: #666666; font-style: italic;">; own constructors.</span>
    elements.username.options.validators.regex.options.pattern <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;/^[a-z]/i&quot;</span>
    elements.username.options.validators.strlen.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;StringLength&quot;</span>
    elements.username.options.validators.strlen.options.min <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;5&quot;</span></pre></div></div>

<p>Bringing it all together, the following is the first version of my login form.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">    <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>login<span style="">&#93;</span></span>
    <span style="color: #666666; font-style: italic;">; General Form Information</span>
    login.action <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;login/submit&quot;</span>
    login.method <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;post&quot;</span>
    login.id <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;login&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Form Decorators</span>
    login.decorators.elements.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;FormElements&quot;</span>
    login.decorators.table.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
    login.decorators.table.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;table&quot;</span>
    login.decorators.form.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Form&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Username Element</span>
    login.elements.username.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;text&quot;</span>
    login.elements.username.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Username:&quot;</span>
    login.elements.username.options.required <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
    login.elements.username.options.validators.alnum.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;alnum&quot;</span>
    login.elements.username.options.validators.regex.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;regex&quot;</span>
    login.elements.username.options.validators.regex.options.pattern <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;/^[a-z]/i&quot;</span>
    login.elements.username.options.validators.strlen.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;StringLength&quot;</span>
    login.elements.username.options.validators.strlen.options.min <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;5&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Password Element</span>
    login.elements.password.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;password&quot;</span>
    login.elements.password.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Password:&quot;</span>
    login.elements.password.options.required <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
    login.elements.password.options.validators.strlen.validator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;StringLength&quot;</span>
    login.elements.password.options.validators.strlen.options.min <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;6&quot;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; Submit Form Element</span>
    login.elements.submit.type <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;submit&quot;</span>
    login.elements.submit.options.label <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Submit&quot;</span>
&nbsp;
    login.elementDecorators.viewHelper <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;ViewHelper&quot;</span>
    login.elementDecorators.errors <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Errors&quot;</span>
&nbsp;
    login.elementDecorators.tableData.decorator.td <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
    login.elementDecorators.tableData.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
    login.elementDecorators.tableData.options.class <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;test2&quot;</span>
&nbsp;
    login.elementDecorators.label.decorator <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Label&quot;</span>
    login.elementDecorators.label.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;td&quot;</span>
&nbsp;
    login.elementDecorators.tableRow.decorator.tr <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;HtmlTag&quot;</span>
    login.elementDecorators.tableRow.options.tag <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;tr&quot;</span></pre></div></div>

<p>This creates a login form with a username and password field along with a submit button.  However, instead of being wrapped in a definition list using definition titles for labels and definition data for input fields, I have wrapped the labels and input fields within a table similar to the google login form.  Notice though, that I have sectioned this form using <em>[login]</em>.  Tthis is so that I can define all my necessary forms in one forms.ini file and load each form by section.  I have also prepended each declaration with <em>login.</em> as a way to keep my form definitions organized and easy to read (to me at least).  </p>
<p>Concluding this guide, I would like to reiterate, how useful I think Zend_Form is as it solves one of the most tedious process for any PHP project; form creation and validation.  I hope it continues to evolve and mature, and I hope others find it as handy as I have.  Although, if anyone has an easier solution, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2008/03/17/using-zend_form-with-zend_config/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Zend Framework, A First Look</title>
		<link>http://www.vayanis.com/2008/03/14/zend-framework-a-first-look/</link>
		<comments>http://www.vayanis.com/2008/03/14/zend-framework-a-first-look/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 14:32:16 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Form]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/2008/03/14/zend-framework-a-first-look/</guid>
		<description><![CDATA[Having used Code Igniter for some small projects at work, I recently decided to take the time to acquaint myself with the Zend Framework(ZF) so that I could build my own comparison between two of the most, in my opinion, developed and used PHP frameworks.  While I love the flexibility and functionality offered by [...]]]></description>
			<content:encoded><![CDATA[<p>Having used <a href="http://www.codeigniter.com">Code Igniter</a> for some small projects at work, I recently decided to take the time to acquaint myself with the <a href="http://framework.zend.com">Zend Framework</a>(ZF) so that I could build my own comparison between two of the most, in my opinion, developed and used PHP frameworks.  While I love the flexibility and functionality offered by ZF, I have become very frustrated and annoyed with some of their documentation.  Even though it is detailed and expansive, it is no where near complete and somewhat frustrating to use.<br />
<span id="more-27"></span><br />
Zend_Form is a great example of this incomplete documentation.  Conceptually, I think the Zend_Form is great. It offers very useful, and much needed functionality for creating and validating forms within pages and although it offers 4 pages of documentation and highlights many features, it barely touches upon one of its most useful features: the ability to create a form by passing the constructor a Zend_Config_Ini object.  In its simplest form this amounts to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$loginForm</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/path/to/form/config'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>This will create a Zend_Form object by passing it a Zend_Config_Ini object.</em></p>
<p>Unfortunately, when you decide to build a custom form using Zend_Config, the documentation on how this actually works, is extremely sparse.  There are three examples of using the Zend_Config, however, they are not commented and there is no explanation as to how it works, there is only a weak reference to PHP object oriented code from which to draw conclusions from.  Maybe, I am too used to the <a href="http://java.sun.com/javase/6/docs/api/">Java API documentation</a>.</p>
<p>Anyways, after a few days with ZF, it has become apparent to me, that ZF is a very well written, powerful, extensible, and versatile PHP framework.  However, due to its incomplete documentation, I would argue that its&#8217; learning curve is fairly high, much higher than Code Igniter&#8217;s.  In time though, I am sure the ZF developers will realize this, and make the effort to provide better documentation.  In the meantime though, I am going to continue to use ZF and hopefully, take it upon myself to provide some insight; a Zend_Form tutorial using Zend_Config is already in the works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2008/03/14/zend-framework-a-first-look/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
