<?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; PHP</title>
	<atom:link href="http://www.vayanis.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vayanis.com</link>
	<description>... a little piece of my mind.</description>
	<lastBuildDate>Wed, 02 Feb 2011 05:05:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>OS X 10.6 (Snow Leopard) – using MAMP/PECL to install PHP extensions</title>
		<link>http://www.vayanis.com/2010/05/19/os-x-10-6-snow-leopard-using-mamppecl-to-install-php-extensions/</link>
		<comments>http://www.vayanis.com/2010/05/19/os-x-10-6-snow-leopard-using-mamppecl-to-install-php-extensions/#comments</comments>
		<pubDate>Wed, 19 May 2010 15:48:25 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[MAMP]]></category>
		<category><![CDATA[Pecl]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/?p=88</guid>
		<description><![CDATA[Need help installing PHP extensions for OS X 10.6 (Snow Leopard) using MAMP and the included pecl binary? Well, you have come to the right place. If you have tried this on its own, you will notice that none of the extensions pecl builds will work with MAMP. This is because MAMP is compiled as [...]]]></description>
			<content:encoded><![CDATA[<p>Need help installing PHP extensions for OS X 10.6 (Snow Leopard) using MAMP and the included pecl binary?  Well, you have come to the right place.  If you have tried this on its own, you will notice that none of the extensions pecl builds will work with MAMP.  This is because MAMP is compiled as a 32-bit binary whereas pecl tries to build 64-bit PHP extensions.</p>
<p>[Update Feb. 1, 2011]</p>
<p>A much easier way to install PECL packages:</p>
<p><code>CFLAGS="-arch i386" ./pecl install</code></p>
<p><del datetime="2011-02-02T05:04:42+00:00">To get pecl working properly, make sure you have <a href="http://developer.apple.com/technologies/tools/xcode.html">Xcode</a> installed on you machine.  Next, you will need to get a copy of MAMP&#8217;s source and prepare it using 32-bit compile flags. You can download the MAMP source from the <a href="http://www.mamp.info/en/downloads/index.html">MAMP download page</a>. Running the .dmg should extract the source. After extracting the source run the following:</del><br />
<span id="more-88"></span><br />
<del datetime="2011-02-02T05:04:42+00:00"><code><br />
mkdir /Applications/MAMP/Library/Include/<br />
mv /path/to/extracted/mamp/source/ /Applications/MAMP/Library/Include/<br />
</code></del></p>
<p><del datetime="2011-02-02T05:04:42+00:00">Next you will want to extract the PHP package and do the following to prepare the package:</del></p>
<p><del datetime="2011-02-02T05:04:42+00:00"><code><br />
mv /Applications/MAMP/Library/Include/extracted_php_source/ /Applications/MAMP/bin/php5/include/php/<br />
cd /Applications/MAMP/bin/php5/include/php/<br />
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Applications/MAMP/bin/php5/bin/php-config<br />
</code></del></p>
<p><del datetime="2011-02-02T05:04:42+00:00">Finally, you now can install pecl extensions with the following command:</del><br />
<del datetime="2011-02-02T05:04:42+00:00"><code><br />
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' /Applications/MAMP/bin/php5/bin/pecl install<br />
</code></del></p>
<p>And that&#8217;s it! Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2010/05/19/os-x-10-6-snow-leopard-using-mamppecl-to-install-php-extensions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<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 &#8217;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[Zend_Form]]></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://173.255.225.117/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>

		<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 Zend_Form in my current [...]]]></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 &#8216;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>32</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 ZF, [...]]]></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>
		<item>
		<title>Sending POST requests with PHP</title>
		<link>http://www.vayanis.com/2007/08/28/sending-post-requests-with-php/</link>
		<comments>http://www.vayanis.com/2007/08/28/sending-post-requests-with-php/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 16:13:06 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/2007/08/28/sending-post-requests-with-php/</guid>
		<description><![CDATA[I recently found myself writing a REST web service, which, in my opinion, is the easiest way to create a web service, for a project at work. Using XML.com&#8217;s How to Create a REST protocol as my Guide, I went to work. However, when I tried to create a service to update some data, I [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found myself writing a REST web service, which, in my opinion, is the easiest way to create a web service, for a project at work.  Using XML.com&#8217;s <a href="http://www.xml.com/pub/a/2004/12/01/restful-web.html">How to Create a REST protocol</a> as my Guide, I went to work.  However, when I tried to create a service to update some data, I wasn&#8217;t sure how to send my data in a POST request using PHP.  After some stumbling around, I found what I was looking for on <a href="http://netevil.org/blog/2006/nov/http-post-from-php-without-curl">Wez Furlong&#8217;s blog</a> which led me to PHP&#8217;s documentation on <a href="http://www.php.net/manual/en/wrappers.http.php">HTTP and HTTPS wrappers</a>.</p>
<p>The following is a code snippet from the HTTP and HTTPS documentation that shows how to easily send data using HTTP POST:<br />
<span id="more-24"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$postdata</span> <span style="color: #339933;">=</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'var1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'some content'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'var2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'doh'</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$opts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http'</span> <span style="color: #339933;">=&gt;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'method'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'header'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Content-type: application/x-www-form-urlencoded'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'content'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$postdata</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$context</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://example.com/submit.php'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Quick Explanation</h3>
<ol>
<li><a href="http://us.php.net/http_build_query">http_build_query</a>: Generates an URL-encoded string from an associative array.  Example: array(&#8216;key1&#8242; => &#8216;value1&#8242;, &#8216;key2&#8242; => &#8216;value2&#8242;) becomes &#8220;key1=value1&#038;key2=value2&#8243;
<p>This properly encodes the data for the post transaction.</p>
</li>
<li><a href="http://us.php.net/manual/en/function.stream-context-create.php">stream_context_create</a>: Creates and returns a resource to a stream context from an associative array of arrays in the format <em>$arr['wrapper']['option'] = $value</em>
<p>This creates a linear output stream to be sent during the request transmission.</p>
</li>
<li><a href="http://us3.php.net/manual/en/function.file-get-contents.php">file_get_contents</a>: Acts exactly like file(); except that it reads an entire file into a string.
<p>This requests a file resource and puts the result into a string.</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2007/08/28/sending-post-requests-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress 2.2&#039;s &#8211; Link Widget Validation Errors</title>
		<link>http://www.vayanis.com/2007/08/09/wordpress-22s-link-widget-validation-errors/</link>
		<comments>http://www.vayanis.com/2007/08/09/wordpress-22s-link-widget-validation-errors/#comments</comments>
		<pubDate>Thu, 09 Aug 2007 05:24:01 +0000</pubDate>
		<dc:creator>Andrew Vayanis</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[XHTML/CSS]]></category>

		<guid isPermaLink="false">http://www.vayanis.com/2007/08/09/wordpress-22s-link-widget-validation-errors/</guid>
		<description><![CDATA[WordPress has really come a long way since I first started using it back when it was version 1.0. It now has a nice clean admin interface (although I am currently using the tiger style admin), a clean and simple installation script, and my new favorites, dynamic sidebars and widgets. However, I noticed that the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.wordpress.org" title="Wordpress homepage">WordPress</a> has really come a long way since I first started using it back when it was version 1.0.  It now has a nice clean admin interface (although I am currently using the <a href="http://orderedlist.com/wordpress-plugins/wp-tiger-administration/" title="Tiger Style Admin">tiger style admin</a>), a clean and simple installation script, and my new favorites, dynamic sidebars and widgets.  However, I noticed that the default links widget creates invalid XHTML markup.  After a few minutes of looking through the XHTML and widgets.php file, I realized that the culprit was in fact a core wordpress bug.  Currently, wordpress creates widgets with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span></pre></div></div>

<p><span id="more-20"></span></p>
<p>This has the nasty effect of creating widget wrappers according to their widget name due to the &#8220;%1$s&#8221;, which isn&#8217;t a deal until you actually have multiple instances of the same widget; in my case, the links widget.  Having figured out the problem, I began searching for solutions online and stumbled upon the actual WordPress bug report in <a href="http://trac.wordpress.org/ticket/4287" title="wordpress bug report: 4287">trac</a>.  The proposed solution was to add the following line of code before the call to wp_list_bookmarks() in wp_widget_links():</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$before_widget</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/id=&quot;[^&quot;]*&quot;/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'id=&quot;%id&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$before_widget</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Unfortunately, this solution wasn&#8217;t good enough for me because I didn&#8217;t want to have to remember this in case the next WordPress release didn&#8217;t fix the bug.  So, after some quick thinking I came up with the following bit of code that can be added to any theme&#8217;s function.php file (I think, I am a bit new to WordPress widgets, in fact, this will be my first).</p>
<p>Edit: This code is actually the exact copy of the widget_links code that ships with wordpress in the widget.php file.  All I did was add the previous fix and moved it into functions.php to create a custom widget.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> widget_my_links<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_db_version</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> EXTR_SKIP<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;">$wp_db_version</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">3582</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// This ONLY works with li/h2 sidebars.</span>
        get_links_list<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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$before_widget</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/id=&quot;[^&quot;]*&quot;/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'id=&quot;%id&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$before_widget</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        wp_list_bookmarks<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'title_before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$before_title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'title_after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'category_before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$before_widget</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'category_after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'show_images'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'linkcat widget'</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>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar_widget'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    register_sidebar_widget<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My Links'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'widget_my_links'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This should add a custom widget called &#8216;My Links&#8217; when you view the Presentation->Widgets menu.  Replace your current Links Widget with this one, and you should be set to go.  No more invalid markup, at least not from the links widget.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vayanis.com/2007/08/09/wordpress-22s-link-widget-validation-errors/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

