<?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>Rob Allen&#039;s DevNotes &#187; Zend Framework</title>
	<atom:link href="http://akrabat.com/category/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://akrabat.com</link>
	<description>Developing PHP software in the Real World, by Rob Allen</description>
	<lastBuildDate>Fri, 12 Mar 2010 16:38:23 +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>Zend Framework, IIS and 500 errors</title>
		<link>http://akrabat.com/zend-framework/zend-framework-iis-and-500-errors/</link>
		<comments>http://akrabat.com/zend-framework/zend-framework-iis-and-500-errors/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 10:42:17 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=954</guid>
		<description><![CDATA[One of the dangers of frameworks in general is that you forget that they do lots of handy things for you.
Consider Zend Framework's default error controller:

&#160;&#160;&#160;public&#160;function&#160;errorAction()
&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$errors&#160;=&#160;$this-&#62;_getParam('error_handler');
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;switch&#160;($errors-&#62;type)&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;case&#160;Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;case&#160;Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;case&#160;Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//&#160;404&#160;error&#160;--&#160;controller&#160;or&#160;action&#160;not&#160;found
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$this-&#62;getResponse()-&#62;setHttpResponseCode(404);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$this-&#62;view-&#62;message&#160;=&#160;'Page&#160;not&#160;found';
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;break;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;default:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//&#160;application&#160;error
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$this-&#62;getResponse()-&#62;setHttpResponseCode(500);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$this-&#62;view-&#62;message&#160;=&#160;'Application&#160;error';
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;break;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//&#160;Log&#160;exception,&#160;if&#160;logger&#160;available
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if&#160;($log&#160;=&#160;$this-&#62;getLog())&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$log-&#62;crit($this-&#62;view-&#62;message,&#160;$errors-&#62;exception);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;//&#160;conditionally&#160;display&#160;exceptions
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if&#160;($this-&#62;getInvokeArg('displayExceptions')&#160;==&#160;true)&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$this-&#62;view-&#62;exception&#160;=&#160;$errors-&#62;exception;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$this-&#62;view-&#62;request&#160;&#160;&#160;=&#160;$errors-&#62;request;
&#160;&#160;&#160;&#160;}


The error handler in ZF will catch any exceptions and route them to the error action in the error controller. This then sets the correct HTTP response code, logs the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the dangers of frameworks in general is that you forget that they do lots of handy things for you.</p>
<p>Consider Zend Framework's default error controller:</p>
<pre class="phpcode"><span style="color: #0000BB">
&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">errorAction</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$errors&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">_getParam</span><span style="color: #007700">(</span><span style="color: #DD0000">'error_handler'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(</span><span style="color: #0000BB">$errors</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">type</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">Zend_Controller_Plugin_ErrorHandler</span><span style="color: #007700">::</span><span style="color: #0000BB">EXCEPTION_NO_ROUTE</span><span style="color: #007700">:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">Zend_Controller_Plugin_ErrorHandler</span><span style="color: #007700">::</span><span style="color: #0000BB">EXCEPTION_NO_CONTROLLER</span><span style="color: #007700">:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">Zend_Controller_Plugin_ErrorHandler</span><span style="color: #007700">::</span><span style="color: #0000BB">EXCEPTION_NO_ACTION</span><span style="color: #007700">:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;404&nbsp;error&nbsp;--&nbsp;controller&nbsp;or&nbsp;action&nbsp;not&nbsp;found
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">setHttpResponseCode</span><span style="color: #007700">(</span><span style="color: #0000BB">404</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Page&nbsp;not&nbsp;found'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;application&nbsp;error
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">setHttpResponseCode</span><span style="color: #007700">(</span><span style="color: #0000BB">500</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Application&nbsp;error'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Log&nbsp;exception,&nbsp;if&nbsp;logger&nbsp;available
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$log&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLog</span><span style="color: #007700">())&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$log</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">crit</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">message</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exception</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;conditionally&nbsp;display&nbsp;exceptions
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getInvokeArg</span><span style="color: #007700">(</span><span style="color: #DD0000">'displayExceptions'</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exception&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exception</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">request&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">request</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;}
</span>
</span></code></pre>
<p>The error handler in ZF will catch any exceptions and route them to the error action in the error controller. This then sets the correct HTTP response code, logs the error and optionally displays it if a config setting is set.</p>
<p>Obviously on our production boxes, we don't display the exceptions, but we do on our local development machines.</p>
<p>IIS has the concept of custom error pages that it displays when the app returns a 4xx or 5xx status code:<br />
<img src="http://akrabat.com/wp-content/uploads/2010-03-Screen-shot-2010-03-04-at-10.07.41.png" alt="Screen shot 2010-03-04 at 10.07.41.png" border="0" width="627" height="334" /></p>
<p>There is also some settings for this page:<br />
<img src="http://akrabat.com/wp-content/uploads/2010-03-Screen-shot-2010-03-04-at-10.28.06.png" alt="Screen shot 2010-03-04 at 10.28.06.png" border="0" width="398" height="367" /></p>
<p>By default this is set so that if you access the site using the <em>localhost</em> domain, then you'll get the ZF error page and if you access the site remotely then you'll get the IIS custom page and won't see the error.</p>
<p>If, like me, you are developing with your IIS in a VM and using the host OS's browser and developer tools, then you need to change the setting to "Detailed":</p>
<p><img src="http://akrabat.com/wp-content/uploads/2010-03-detailed-iis-errors.png" alt="detailed-iis-errors.png" border="0" width="403" height="369" /></p>
<p>Now you can see your exceptions and it doesn't look like PHP has crashed :)</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/zend-framework-iis-and-500-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework Tutorial for ZF 1.10</title>
		<link>http://akrabat.com/zend-framework/zend-framework-tutorial-for-zf-1-10/</link>
		<comments>http://akrabat.com/zend-framework/zend-framework-tutorial-for-zf-1-10/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 21:52:07 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=928</guid>
		<description><![CDATA[Zend Framework 1.10, was released a week or so ago.
As a result, I have updated my Zend Framework tutorial so that it is completely current. The main change I made was to remove the _init methods in the Bootstrap as they are no longer needed. I also take advantage of the new features of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://framework.zend.com/">Zend Framework 1.10</a>, was released a week or so ago.</p>
<p>As a result, I have updated my <a href="http://akrabat.com/zend-framework-tutorial">Zend Framework tutorial</a> so that it is completely current. The main change I made was to remove the _init methods in the Bootstrap as they are no longer needed. I also take advantage of the new features of the <tt>zf</tt> tool to enable layouts and create forms. It's a shame that it gets the class name of the form wrong though!</p>
<p><img src="http://akrabat.com/wp-content/uploads/zf-tutorial_17-300x240.png" alt="Screen short of Zend Framework tutorial" title="Listing albums in Zend Framework tutorial" width="300" height="240" class="alignright" /></p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/zend-framework-tutorial-for-zf-1-10/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Determining if a ZF view helper exists</title>
		<link>http://akrabat.com/zend-framework/determining-if-a-zf-view-helper-exists/</link>
		<comments>http://akrabat.com/zend-framework/determining-if-a-zf-view-helper-exists/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 16:38:14 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=900</guid>
		<description><![CDATA[This is another one of those posts that exists as a record for me so I can find it again if i need it!
If you need to know whether a view helper exists before you call it, one way is to write a simple view helper to tell you:

class&#160;App_View_Helper_HelperExists&#160;extends&#160;Zend_View_Helper_Abstract
{
&#160;&#160;&#160;&#160;function&#160;helperExists($name)&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return&#160;(bool)$this-&#62;view-&#62;getPluginLoader('helper')-&#62;load($name,&#160;false);
&#160;&#160;&#160;&#160;}
}


You can then use it in a [...]]]></description>
			<content:encoded><![CDATA[<p>This is another one of those posts that exists as a record for me so I can find it again if i need it!</p>
<p>If you need to know whether a view helper exists before you call it, one way is to write a simple view helper to tell you:</p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">App_View_Helper_HelperExists&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_View_Helper_Abstract
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">helperExists</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;(bool)</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getPluginLoader</span><span style="color: #007700">(</span><span style="color: #DD0000">'helper'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>You can then use it in a view scripts like this:</p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">helperExists</span><span style="color: #007700">(</span><span style="color: #DD0000">'doMagic'</span><span style="color: #007700">))&nbsp;{&nbsp;echo&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">doMagic</span><span style="color: #007700">();&nbsp;}&nbsp;</span><span style="color: #0000BB">?&gt;
</span>
</span></code></pre>
<p>As Jeremy mentions in the comments, this code came out of a discussion on the <a href="http://www.phpnw.org.uk/">PHPNW</a> IRC channel #phpnw</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/determining-if-a-zf-view-helper-exists/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Custom Zend_Application Resources</title>
		<link>http://akrabat.com/zend-framework/custom-zend_application-resources/</link>
		<comments>http://akrabat.com/zend-framework/custom-zend_application-resources/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 07:12:57 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=889</guid>
		<description><![CDATA[Sooner or later, you want to leverage Zend_Application better by creating your own resource plugins. This lets you reuse your initialisation work in multiple application that much easier and keeps your Boostrap class that much shorter!
In my case, I wanted to create a resource for CouchDb that checked that the database was created and if [...]]]></description>
			<content:encoded><![CDATA[<p>Sooner or later, you want to leverage <a href="http://weierophinney.net/matthew/archives/230-Quick-Start-to-Zend_Application_Bootstrap.html"><tt>Zend_Application</tt></a> better by creating your own resource plugins. This lets you reuse your initialisation work in multiple application that much easier and keeps your Boostrap class that much shorter!</p>
<p>In my case, I wanted to create a resource for <a href="http://couchdb.apache.org/">CouchDb</a> that checked that the database was created and if not, create it.</p>
<p>Creating your own plugin is easy enough. The obvious place is library/App/Application/Resource and a typical resource would look like this:</p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">App_Application_Resource_Couchdb&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_Application_Resource_ResourceAbstract
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Defined&nbsp;by&nbsp;Zend_Application_Resource_Resource
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;Phly_Couch|null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">init</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;do&nbsp;stuff&nbsp;here&nbsp;to&nbsp;init&nbsp;CouchDB
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOptions</span><span style="color: #007700">();&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;$options&nbsp;contains&nbsp;everything&nbsp;under&nbsp;'resources.couchdb'&nbsp;in&nbsp;application.ini
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}
}
</span>
</span></code></pre>
<p>You then need to tell Zend_Application about your new plugins. This is done with this line in application.ini:</p>
<pre class="phpcode"><span style="color: #0000BB">
pluginPaths</span><span style="color: #007700">.</span><span style="color: #0000BB">App_Application_Resource_&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"App/Application/Resource"
</span>
</span></code></pre>
<p>You can now have as many resource plugins as you like within the <tt>App_Application_Resource_</tt> class-space.</p>
<p>Also, Matthew Weier O'Phinney has also written an article on <a href="http://www.weierophinney.net/matthew/archives/230-Quick-Start-to-Zend_Application_Bootstrap.html">Zend_Application</a> which you should read too.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/custom-zend_application-resources/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zend Framework on a shared host</title>
		<link>http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/</link>
		<comments>http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 07:31:24 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=873</guid>
		<description><![CDATA[When you deploy a Zend Framework website to a shared host, you usually cannot change the DocumentRoot to point at the public/ folder of the website. As a result the URL to the website is now http://www.example.com/public/. This doesn't look very professional, so we'd like to remove it.
The easiest way, given a ZF project created [...]]]></description>
			<content:encoded><![CDATA[<p>When you deploy a Zend Framework website to a shared host, you usually cannot change the DocumentRoot to point at the <tt>public/</tt> folder of the website. As a result the URL to the website is now http://www.example.com/public/. This doesn't look very professional, so we'd like to remove it.</p>
<p>The easiest way, given a ZF project created using <tt>Zend_Tool</tt> is this:</p>
<h3>Create /index.php</h3>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php&nbsp;
define</span><span style="color: #007700">(</span><span style="color: #DD0000">'RUNNING_FROM_ROOT'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);
include&nbsp;</span><span style="color: #DD0000">'public/index.php'</span><span style="color: #007700">;
</span>
</span></code></pre>
<p>This uses the <tt>index.php</tt> already created by <tt>Zend_Tool</tt> and means that we don't have to change anything if we move to a VPS host where we can set the DocumentRoot directly to <tt>public/</tt>.</p>
<h3>Create /.htaccess</h3>
<p></code>
<pre class="phpcode"><span style="color: #0000BB">
SetEnv&nbsp;APPLICATION_ENV&nbsp;development

RewriteEngine&nbsp;On
RewriteRule&nbsp;</span><span style="color: #007700">.*&nbsp;</span><span style="color: #0000BB">index</span><span style="color: #007700">.</span><span style="color: #0000BB">php
</span>
</span></code></pre>
<p>We create a <tt>.htaccess</tt> file that redirects every request to index.php. We want to do this so that no one can try and read <tt>application/configs/application.ini</tt>.  Obviously, set the <tt>APPLICATION_ENV</tt> to the correct value!</p>
<h3>Referencing public facing files</h3>
<p>Having created a very aggressive, rewrite rule, what about CSS/JS/image files though? </p>
<p>Fortunately, we already have a <tt>.htaccess</tt> file in the <tt>public/</tt> folder that correctly handles this situation. As Apache will execute the .htaccess files in the deepest directory it finds, any reference to a public facing file within the <tt>public/</tt> folder will correctly be served.</p>
<p>You do have to be aware of this when referencing public facing files though and add the <tt>/public</tt> to the baseUrl yourself. </p>
<p>For example, you may set up your CSS file and other view settings within a Front Controller plugin like this:</p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">App_Controller_Plugin_View&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_Controller_Plugin_Abstract
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">dispatchLoopStartup</span><span style="color: #007700">(</span><span style="color: #0000BB">Zend_Controller_Request_Abstract&nbsp;$request</span><span style="color: #007700">)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$frontController&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Zend_Controller_Front</span><span style="color: #007700">::</span><span style="color: #0000BB">getInstance</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$view&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$frontController</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParam</span><span style="color: #007700">(</span><span style="color: #DD0000">'bootstrap'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getResource</span><span style="color: #007700">(</span><span style="color: #DD0000">'view'</span><span style="color: #007700">);&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">doctype</span><span style="color: #007700">(</span><span style="color: #DD0000">'XHTML1_STRICT'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$baseUrl&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getBaseUrl</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">defined</span><span style="color: #007700">(</span><span style="color: #DD0000">'RUNNING_FROM_ROOT'</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$baseUrl&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">'/public'</span><span style="color: #007700">;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headLink</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">appendStylesheet</span><span style="color: #007700">(</span><span style="color: #0000BB">$baseUrl&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'/css/main.css'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headLink</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">appendStylesheet</span><span style="color: #007700">(</span><span style="color: #0000BB">$baseUrl&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'/css/screen.css'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'screen'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">headLink</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">appendStylesheet</span><span style="color: #007700">(</span><span style="color: #0000BB">$baseUrl&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'/css/print.css'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'print'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;
}
</span>
</span></code></pre>
<p><span style="font-size: 0.95em;">(This code assumes you have added a <tt>resources.view[] = ""</tt> to your application.ini)</span></p>
<p>As we have a constant that tells us if we're running from the root, we can dynamically add the <tt>/public</tt> into the URL. If we change to a host where the DocumentRoot is set directly to the <tt>public/</tt> folder, then we don't need to change our code.</p>
<p>That's it. Your Zend Framework application works nicely with shared hosts.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Accessing your configuration data in application.ini</title>
		<link>http://akrabat.com/zend-framework/accessing-your-configuration-data-in-application-ini/</link>
		<comments>http://akrabat.com/zend-framework/accessing-your-configuration-data-in-application-ini/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 12:11:53 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=837</guid>
		<description><![CDATA[Zend_Application will read the data in your application.ini and make it available from your bootstrap's getOptions() method. It then sets the bootstrap as a parameter in the front controller. Note that the top level keys are all normalised to lowercase too.
You can then retrieve the options in a number of ways.
In the controller you can [...]]]></description>
			<content:encoded><![CDATA[<p><tt>Zend_Application</tt> will read the data in your application.ini and make it available from your bootstrap's getOptions() method. It then sets the bootstrap as a parameter in the front controller. Note that the top level keys are all normalised to lowercase too.</p>
<p>You can then retrieve the options in a number of ways.</p>
<p>In the controller you can do this:</p>
<pre class="phpcode"><span style="color: #0000BB">
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">someAction</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bootstrap&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getInvokeArg</span><span style="color: #007700">(</span><span style="color: #DD0000">'bootstrap'</span><span style="color: #007700">);&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$bootstrap</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOptions</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;}
</span>
</span></code></pre>
<p>Outside of the controller you can do this:</p>
<pre class="phpcode"><span style="color: #0000BB">
&nbsp;&nbsp;&nbsp;&nbsp;$bootstrap&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">Zend_Controller_Front</span><span style="color: #007700">::</span><span style="color: #0000BB">getInstance</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getParam</span><span style="color: #007700">(</span><span style="color: #DD0000">'bootstrap'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$bootstrap</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOptions</span><span style="color: #007700">();
</span>
</span></code></pre>
<p>One downside is that <tt>$options</tt> is a nested array, and not a <tt>Zend_Config</tt> object. If you prefer to work with a Zend_Config object you need to create it yourself as <tt>Zend_Application</tt> discards the one it creates. The easiest way to do this is to create a new method in your bootstrap to create the <tt>Zend_Config</tt> object and store to the registry.</p>
<pre class="phpcode"><span style="color: #0000BB">
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">protected&nbsp;function&nbsp;</span><span style="color: #0000BB">_initConfig</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$config&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Zend_Config</span><span style="color: #007700">(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOptions</span><span style="color: #007700">());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">Zend_Registry</span><span style="color: #007700">::</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'config'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$config</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$config</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;}
</span>
</span></code></pre>
<p>You can then get at your config data wherever you need it. Try not to depend too much on <tt>Zend_Registry</tt> keys though, as it can make testing harder.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/accessing-your-configuration-data-in-application-ini/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Zend Framework URL Rewriting in IIS6</title>
		<link>http://akrabat.com/zend-framework/zend-framework-url-rewriting-in-iis6/</link>
		<comments>http://akrabat.com/zend-framework/zend-framework-url-rewriting-in-iis6/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 07:55:22 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[zendframework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=798</guid>
		<description><![CDATA[I've written before about URL rewriting with IIS7's URL Rewrite module.
IIS6, which ships with Windows Server 2003 does not have this module though and guess which version my client's IT dept run? As usual, they wouldn't install ISAPI_Rewrite or one of the other solutions for me. In the past, I've simply written a new router [...]]]></description>
			<content:encoded><![CDATA[<p>I've <a href="http://akrabat.com/2009/05/11/zend-framework-url-rewriting-in-iis7/">written before</a> about URL rewriting with IIS7's <a href="http://www.iis.net/extensions/URLRewrite">URL Rewrite</a> module.</p>
<p>IIS6, which ships with Windows Server 2003 does not have this module though and guess which version my client's IT dept run? As usual, they wouldn't install ISAPI_Rewrite or one of the other solutions for me. In the past, I've simply written a <a href="http://akrabat.com/2008/06/03/zend-framework-urls-without-mod_rewrite/">new router</a> that creates URLs with normal GET variables, but this is ugly and I wanted better.</p>
<p>One thing IIS6 does let you do is configure a URL to be called upon a 404 error, which then allows you to have "pretty" URLs and be able to route them.</p>
<p>Firstly, I set up the URL handler in the IIS Manager:</p>
<p><img src="http://akrabat.com/wp-content/uploads/2009-07-Screen-shot-2009-11-13-at-07.46.59-1.jpg" alt="Screen shot 2009-11-13 at 07.46.59-1.jpg" border="0" width="400" height="387" /></p>
<p>This will result in all unrecognised URLs being redirected to index.php. The standard <tt>Zend_Controller_Request_Http</tt> object will automatically extract the URL and routing works as expected.</p>
<p>However, there are three problems:</p>
<ol>
<li>The $_POST array is always empty</li>
<li>$_SERVER['REQUEST_METHOD'] is always GET, even for a post request</li>
<li>The first key in $_GET has been mangled by IIS</li>
</ol>
<p>As Zend Framework wraps up the request into a Request object, this is fairly simple to work around by creating our own Request object.</p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">App_Controller_Request_Iis404&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_Controller_Request_Http
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Constructor
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;If&nbsp;a&nbsp;$uri&nbsp;is&nbsp;passed,&nbsp;the&nbsp;object&nbsp;will&nbsp;attempt&nbsp;to&nbsp;populate&nbsp;itself&nbsp;using
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;that&nbsp;information.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;string|Zend_Uri&nbsp;$uri
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;void
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@throws&nbsp;Zend_Controller_Request_Exception&nbsp;when&nbsp;invalid&nbsp;URI&nbsp;passed
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;As&nbsp;Zend_Controller_Request_Http&nbsp;accesses&nbsp;the&nbsp;superglobals&nbsp;directly,&nbsp;we
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;will&nbsp;have&nbsp;to&nbsp;write&nbsp;into&nbsp;$_GET&nbsp;and&nbsp;$_POST&nbsp;directly

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;The&nbsp;post&nbsp;variables&nbsp;can&nbsp;be&nbsp;accessed&nbsp;from&nbsp;php://input
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$input&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://input'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$input&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">urldecode</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">parse_str</span><span style="color: #007700">(</span><span style="color: #0000BB">$input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;fix&nbsp;$_GET
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">$_GET&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$key</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #DD0000">'404;'</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;special&nbsp;key&nbsp;created&nbsp;by&nbsp;IIS&nbsp;-&nbsp;the&nbsp;actual&nbsp;key&nbsp;name&nbsp;is&nbsp;after&nbsp;the&nbsp;?
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bits&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'?'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$bits</span><span style="color: #007700">)&nbsp;&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #0000BB">$bits</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]]&nbsp;=&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$uri</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Return&nbsp;the&nbsp;method&nbsp;by&nbsp;which&nbsp;the&nbsp;request&nbsp;was&nbsp;made
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;string
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">getMethod</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!empty(</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #DD0000">'POST'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">getMethod</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>We start by reading the <tt>php://input</tt> stream which on a POST request will hold the POST variables. We can then transfer them to the <tt>$_POST</tt> array. Similarly, the key in the $_GET array that has been mangled, is easy to detect as it starts with '404;'. We can then find the ? and the part after it is the real key, so we create a new $_GET element for that item. Finally, we override <tt>getMethod()</tt> and return 'POST' if there are any elements in $_POST.</p>
<p>To use a custom Request object, you need to create an _init method in your Bootstrap:</p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Bootstrap&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_Application_Bootstrap_Bootstrap
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">_initIis404RequestObject</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bootstrap</span><span style="color: #007700">(</span><span style="color: #DD0000">'frontController'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$frontController&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResource</span><span style="color: #007700">(</span><span style="color: #DD0000">'frontController'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$frontController</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRequest</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">[</span><span style="color: #DD0000">'frontController'</span><span style="color: #007700">][</span><span style="color: #DD0000">'requestClass'</span><span style="color: #007700">]);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
</span>
</span></code></pre>
<p>Zend Framework's standard URLs now work nicely with IIS6 on Window Server 2003.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/zend-framework-url-rewriting-in-iis6/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Three years of my Zend Framework Tutorial</title>
		<link>http://akrabat.com/site/three-years-of-my-zend-framework-tutorial/</link>
		<comments>http://akrabat.com/site/three-years-of-my-zend-framework-tutorial/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 06:30:42 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Me]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=714</guid>
		<description><![CDATA[Three years ago today, I published my first Getting Started with Zend Framework tutorial. This was the announcement. Back then, Zend Framework was at version 0.1.5 and a considerably smaller download than now :) 
Three years later and I haven't lost my enthusiasm for Zend Framework as you can tell since the latest version of [...]]]></description>
			<content:encoded><![CDATA[<p>Three years ago today, I published my first <em>Getting Started with Zend Framework</em> tutorial. This was the <a href="/2006/08/16/my-take-on-a-zend-framework-tutorial/">announcement</a>. Back then, Zend Framework was at version 0.1.5 and a considerably smaller download than now :) </p>
<p>Three years later and I haven't lost my enthusiasm for Zend Framework as you can tell since the <a href="http://akrabat.com/zend-framework-tutorial/">latest version of the tutorial</a> supports ZF 1.8 and 1.9 and uses the new features like Zend_Application and the command line Zend_Tool scripts. And I wrote a <a href="http://www.zendframeworkinaction.com">Zend Framework book</a>!</p>
<p>I wonder what will happen in the next three years?!</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/site/three-years-of-my-zend-framework-tutorial/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>My tutorial is compatible with Zend Framework 1.9</title>
		<link>http://akrabat.com/zend-framework/my-tutorial-is-compatible-with-zend-framework-1-9/</link>
		<comments>http://akrabat.com/zend-framework/my-tutorial-is-compatible-with-zend-framework-1-9/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 20:17:20 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=726</guid>
		<description><![CDATA[I've just updated my tutorial to version 1.6.3 after checking that it is still compatible with version 1.9 of Zend Framework.
The only changes I had to make were:

ZF 1.9 comes with its own BaseUrl view helper, so there's no need to write our own.
ZF 1.9.0's command line tool doesn't work on Windows. I've created patches [...]]]></description>
			<content:encoded><![CDATA[<p>I've just updated my <a href="/zend-framework-tutorial/">tutorial</a> to version 1.6.3 after checking that it is still compatible with version 1.9 of Zend Framework.</p>
<p>The only changes I had to make were:</p>
<ul>
<li>ZF 1.9 comes with its own <tt>BaseUrl</tt> view helper, so there's no need to write our own.</li>
<li>ZF 1.9.0's command line tool doesn't work on Windows. I've created patches on issues <a href="http://framework.zend.com/issues/browse/ZF-7464">ZF-7464</a> and <a href="http://framework.zend.com/issues/browse/ZF-7465">ZF-7465</a>. I'm sure this will be sorted with 1.9.1 though.</li>
</ul>
<p>ZF 1.9 looks like a really solid release too.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/my-tutorial-is-compatible-with-zend-framework-1-9/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bootstrapping modules in ZF 1.8 and up</title>
		<link>http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/</link>
		<comments>http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 19:36:00 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=682</guid>
		<description><![CDATA[I've started to play with modules in a Zend Framework 1.8 application as the new autoloader means that all your model directories no long have to be on the include_path for autoloading to work. What I'm specifically interested in is being able to instantiate a model that is within a module from within another module. [...]]]></description>
			<content:encoded><![CDATA[<p>I've started to play with modules in a Zend Framework 1.8 application as the new autoloader means that all your model directories no long have to be on the include_path for autoloading to work. What I'm specifically interested in is being able to instantiate a model that is within a module from within another module. </p>
<p>Setting it all up isn't that hard, but I couldn't find a concise description, so these are my notes on it.</p>
<p>Start by creating a ZF application using the <tt>zf</tt> command line tool:</p>
<pre>
$ zf create project myproject
</pre>
<p>Don't forget to put a copy of ZF 1.8 into the <tt>library</tt> directory or ensure that it is on the include_path.</p>
<p>We now need a module:</p>
<pre>
$ cd myproject
$ zf create module blog
</pre>
<p>This will create all the relevant directories in myproject/application/modules/blog. We create a simple model within the <tt>blog</tt> module:</p>
<p><em>File: myproject/application/modules/blog/models/Info.php</em></p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php

</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Blog_Model_Info
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">getInfo</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;the&nbsp;info&nbsp;about&nbsp;the&nbsp;Blog&nbsp;module"</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>The naming is important. First we have the module name, then we have the word "Model" then we have the name of the model itself. It is important that this model's name matches the filename too.</p>
<p>We want to use this model within the index action of the Index controller like this:</p>
<p><em>File: myproject/application/controller/IndexController.php</em></p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php

</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">IndexController&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_Controller_Action
</span><span style="color: #007700">{

&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">init</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Initialize&nbsp;action&nbsp;controller&nbsp;here&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}

&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">indexAction</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;action&nbsp;body
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$info&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Blog_Model_Info</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">blogInfo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$info</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getInfo</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>I've included the entire class here; most of it is auto-generated, you just need to add the two new lines under the <tt>// action body</tt> comment. Having assigned something to the view, we should display it so we can prove it worked:</p>
<p><em>File: myproject/application/views/scripts/index/index.phtml</em></p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">blogInfo</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">?&gt;
</span>
</span></code></pre>
<p>(Note that we replace the pretty ZF welcome page.)</p>
<p>At this point we get an error:<br />
<img src="http://akrabat.com/wp-content/uploads/2009-07-blog_model_module_failure.png" alt="blog_model_module_failure.png" border="0" width="591" height="372" /><br />
<!-- <tt><br />
Fatal error: Class 'Blog_Model_Info' not found in<br />
/usr/local/zend/apache2/htdocs/myproject/application/controllers/IndexController.php on line 14<br />
 --></p>
<p>This is because we haven't told the autoloader about our module's model's directory. This is done using <tt>Zend_Application</tt>'s bootstrapping. There are two parts:</p>
<p>Firstly we have to add a line to <tt>application.ini</tt> enable modules at the end of the <tt>[production]</tt> section:</p>
<p><em>File: myproject/application/configs/application.ini</em><strong>
<pre class="phpcode"><span style="color: #0000BB">resources</span><span style="color: #007700">.</span><span style="color: #0000BB">frontController</span><span style="color: #007700">.</span><span style="color: #0000BB">moduleDirectory&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">APPLICATION_PATH&nbsp;</span><span style="color: #DD0000">"/modules"
</span><span style="color: #0000BB">resources</span><span style="color: #007700">.</span><span style="color: #0000BB">modules</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">""</span>
</span></code></pre>
<p></strong></p>
<p>Secondly, we need to add a Bootstrap class to our module:</p>
<p><em>File: myproject/application/modules/blog/Bootstrap.php</em><br />
<strong>
<pre class="phpcode"><span style="color: #0000BB">&lt;?php

</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Blog_Bootstrap&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Zend_Application_Module_Bootstrap
</span><span style="color: #007700">{

}
</span>
</span></code></pre>
<p></strong></p>
<p>Again, the naming is important; the class name must be <tt>{module name}_Bootstrap</tt> and it must extend <tt>Zend_Application_Module_Bootstrap</tt>. It must be stored in a file called <tt>Bootstrap.php</tt> within the root of the module.</p>
<p>That's it. If you refresh the page, you'll get the data from the Blog module's Info model within the default module:</p>
<p><img src="http://akrabat.com/wp-content/uploads/2009-07-blog_model_module_success.png" alt="blog_model_module_success.png" border="0" width="591" height="360" /></p>
<p>All in all, it's not difficult at all, but if you don't have those two lines in <tt>application.ini</tt> and define a module bootstrap class, then it doesn't work.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
	</channel>
</rss>
