<?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>Phil Brown&#039;s Web Development Blog</title>
	<atom:link href="http://blog.philipbrown.id.au/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.philipbrown.id.au</link>
	<description></description>
	<lastBuildDate>Mon, 05 Dec 2011 22:22:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Where&#8217;s my Front Controller?</title>
		<link>http://blog.philipbrown.id.au/2011/10/wheres-my-front-controller/</link>
		<comments>http://blog.philipbrown.id.au/2011/10/wheres-my-front-controller/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 04:43:05 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[application resource plugin]]></category>
		<category><![CDATA[front controller]]></category>
		<category><![CDATA[resource plugins]]></category>

		<guid isPermaLink="false">http://blog.philipbrown.id.au/?p=176</guid>
		<description><![CDATA[I&#8217;ve been spending a bit of time on StackOverflow lately and have even earned myself a bronze &#8220;Zend Framework&#8221; badge. One thing I continually see in questions surrounding the bootstrap process and resource plugins is this&#8230; protected function _initSomething&#40;&#41; &#123; $front = FrontController::getInstance&#40;&#41;; &#160; // and so on This is not the right way to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending a bit of time on StackOverflow lately and have even earned myself a bronze &#8220;Zend Framework&#8221; badge.</p>
<p>One thing I continually see in questions surrounding the bootstrap process and resource plugins is this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> FrontController<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;">// and so on</span></pre></div></div>

<p>This is not the right way to fetch the Front Controller. For starters, at this stage it may not have been bootstrapped, meaning options supplied via configuration may not have been applied.</p>
<p>Following the <a href="http://framework.zend.com/manual/en/zend.application.theory-of-operation.html#zend.application.theory-of-operation.bootstrap.dependency-tracking">Zend Application &#8211; Theory of Operation &#8211; Dependency Tracking</a> documentation, this is the correct method&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FrontController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> this<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FrontController'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// and so on</span></pre></div></div>

<p>The same logic applies to any required resource; Bootstrap it first then fetch it from the application container. Simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2011/10/wheres-my-front-controller/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Awesome Pagination with ZF, Paginator, AjaxContext and the HTML5 History API</title>
		<link>http://blog.philipbrown.id.au/2011/03/awesome-pagination-with-zf-paginator-ajaxcontext-and-the-html5-history-api/</link>
		<comments>http://blog.philipbrown.id.au/2011/03/awesome-pagination-with-zf-paginator-ajaxcontext-and-the-html5-history-api/#comments</comments>
		<pubDate>Thu, 10 Mar 2011 13:09:32 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[AjaxContext]]></category>
		<category><![CDATA[History API]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Pagination]]></category>
		<category><![CDATA[Zend_Paginator]]></category>

		<guid isPermaLink="false">http://blog.philipbrown.id.au/?p=159</guid>
		<description><![CDATA[One of my favourite components in Zend Framework is the AjaxContext action helper. This little beauty allows you to intercept AJAX requests and deliver a different view based on request parameters, all without touching a single line of action code. One scenario where this has always appealed to me is in paginating data. Why reload [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favourite components in Zend Framework is the <a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch.ajaxcontext">AjaxContext action helper</a>. This little beauty allows you to intercept AJAX requests and deliver a different view based on request parameters, all without touching a single line of action code.</p>
<p>One scenario where this has always appealed to me is in paginating data. Why reload an entire document each time you page through a dataset when you can use AJAX to fetch just the next page.</p>
<p>Now introduce the HTML5 History API, and all of a sudden you&#8217;ve got AJAX data updates with navigable, bookmarkable URLs.</p>
<p>In this article, I&#8217;m going to step through creating a paging controller action that updates the paged data via AJAX and maintains URL location for browsers that support the History API.</p>
<p>If you want to play along at home, all code used in this demo is available on github, with each stage represented by its own branch. Get the code at <a href="https://github.com/philBrown/Awesome-Pagination-Demo">https://github.com/philBrown/Awesome-Pagination-Demo</a> and checkout the &#8220;html-only&#8221; branch</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>philBrown<span style="color: #000000; font-weight: bold;">/</span>Awesome-Pagination-Demo.git
<span style="color: #7a0874; font-weight: bold;">cd</span> Awesome-Pagination-Demo
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> origin<span style="color: #000000; font-weight: bold;">/</span>html-only</pre></div></div>

<p>To start with, we have a vanilla ZF project with a layout and simple controller action that instantiates a paginator object (using the array adapter for this demo), grabs the &#8220;page&#8221; parameter from the request and assigns the paginator to the view.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$paginator</span> <span style="color: #339933;">=</span> Zend_Paginator<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModels</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$paginator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCurrentPageNumber</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$paginator</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Our view then displays the paginationControl helper</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$paginationControl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginationControl</span><span style="color: #009900;">&#40;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paginator</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'All'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_partials/paginator.phtml'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div class=&quot;pagination-control&quot;&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$paginationControl</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;</pre></div></div>

<p>and a table with our data, looping over each item in the paginator.</p>
<p>What we end up with is something like this</p>
<p><a href="http://blog.philipbrown.id.au/wp-content/uploads/2011/03/Screen-shot-2011-03-10-at-4.13.53-PM.png"><img src="http://blog.philipbrown.id.au/wp-content/uploads/2011/03/Screen-shot-2011-03-10-at-4.13.53-PM-300x146.png" alt="" title="Screen shot 2011-03-10 at 4.13.53 PM" width="300" height="146" class="alignnone size-medium wp-image-162" /></a></p>
<p>Clicking on each paginator link loads an entirely new page with the requested data. Not horrible, but could be better.</p>
<p>Now checkout the &#8220;ajax-loading&#8221; branch</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> origin<span style="color: #000000; font-weight: bold;">/</span>ajax-loading</pre></div></div>

<p>Our layout now includes the inlineScript helper with a link to jQuery on the Google CDN. The controller now initialises the AjaxContext helper to allow &#8220;html&#8221; AJAX requests for the index action.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">ajaxContext</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addActionContext</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#41;</span>
                               <span style="color: #339933;">-&gt;</span><span style="color: #004000;">initContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The view has also been changed. We&#8217;ve added a link to our pagination JavaScript file (more on this later) and the guts of the view (pagination controls and data) has been moved into a new file <code>index.ajax.phtml</code> which is referenced using the render method.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">// index.phtml
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">inlineScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">appendFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'js/paginator.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;div class=&quot;paged-data-container&quot;&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index/index.ajax.phtml'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;</pre></div></div>

<p>The index.ajax.phtml file is the one delivered via the AjaxContext helper when an XMLHTTPRequest is intercepted with the &#8220;html&#8221; format parameter present. Including it in the default template caters for the first page load.</p>
<p>Now on to our JavaScript file. All this file needs to do is catch click events on any of the paginator links and fetch the contents via AJAX, repopulating the paginator controls and data.</p>
<p>In essence, it looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.pagination-control'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> container <span style="color: #339933;">=</span> link.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.paged-data-container'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>link.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> format<span style="color: #339933;">:</span> <span style="color: #3366CC;">'html'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            container.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We&#8217;re using the &#8220;live&#8221; binding as each AJAX load replaces the paginator controls. The <code>{ format: 'html' }</code> parameter is added to the request to trigger the right context switch in the controller.</p>
<p>So now we have a basic AJAX paginator. The only problem here is that each page loads under the same URL. There&#8217;s also little visual feedback to let the user know the data is changing.</p>
<p>Taking a leaf out of GitHub&#8217;s &#8220;Tree Slider&#8221;, if you checkout the &#8220;ajax-loading-animations&#8221; branch, you&#8217;ll see some nifty left (next) and right (previous) scrolling.</p>
<p>So now we come to the final stage, utilising the HTML5 History API to add stateful URLs for each AJAX data load.</p>
<p>Checkout the master branch to see the code.</p>
<p>The gist of this is to use the <code>history.pushState</code> method to add history records on click and bind an event handler to the &#8220;popstate&#8221; event to catch navigation (back / forward) button presses.</p>
<p>The end result looks like this &#8211; <a href="http://apps.philipbrown.id.au/awesome-pagination/">http://apps.philipbrown.id.au/awesome-pagination/</a></p>
<p>Whilst it&#8217;s certainly not as snazzy as GitHub&#8217;s Tree Slider, it&#8217;s a step in the right direction.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2011/03/awesome-pagination-with-zf-paginator-ajaxcontext-and-the-html5-history-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LabelFor helper with custom text</title>
		<link>http://blog.philipbrown.id.au/2010/10/labelfor-helper-with-custom-text/</link>
		<comments>http://blog.philipbrown.id.au/2010/10/labelfor-helper-with-custom-text/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 05:35:00 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET MVC]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[labelfor]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://blog.philipbrown.id.au/?p=154</guid>
		<description><![CDATA[It&#8217;s been a long time between posts and as evidenced by the new category, I&#8217;ve been busy. Of late, I&#8217;ve been really getting into the .NET MVC framework and for some things, it&#8217;s been an absolute wonder. For others, I&#8217;d love to point the developers to some Zend Framework features. In keeping with the tradition [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time between posts and as evidenced by the new category, I&#8217;ve been busy.</p>
<p>Of late, I&#8217;ve been really getting into the .NET MVC framework and for some things, it&#8217;s been an absolute wonder. For others, I&#8217;d love to point the developers to some Zend Framework features.</p>
<p>In keeping with the tradition of blogging about things that I discover in my day-to-day development work, I&#8217;d like to contribute this little snippet of code that&#8217;s come in very handy for me.</p>
<p>The <code>LabelFor</code> helper in .NET MVC gives you a nice, easy way to set a strongly typed label for your model properties. One problem though, you can&#8217;t set the label text.</p>
<p>Whilst you can use the <code>[DisplayName]</code> component model attribute, this doesn&#8217;t help if say, your model is part of a collection and needs a unique label. It also feels a bit odd putting presentation data in the model but that&#8217;s just me.</p>
<p>So here&#8217;s my very simple override</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> MvcHtmlString LabelFor<span style="color: #008000;">&lt;</span>TModel, TProperty<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> HtmlHelper<span style="color: #008000;">&lt;</span>TModel<span style="color: #008000;">&gt;</span> helper, Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span>TModel, TProperty<span style="color: #008000;">&gt;&gt;</span> expression, <span style="color: #6666cc; font-weight: bold;">string</span> text<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> propertyName <span style="color: #008000;">=</span> ExpressionHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExpressionText</span><span style="color: #008000;">&#40;</span>expression<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    TagBuilder label <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TagBuilder<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;label&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    label<span style="color: #008000;">.</span><span style="color: #0000FF;">SetInnerText</span><span style="color: #008000;">&#40;</span>text<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    label<span style="color: #008000;">.</span><span style="color: #0000FF;">MergeAttribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;for&quot;</span>, helper<span style="color: #008000;">.</span><span style="color: #0000FF;">ViewData</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TemplateInfo</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetFullHtmlFieldId</span><span style="color: #008000;">&#40;</span>propertyName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> MvcHtmlString<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>label<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2010/10/labelfor-helper-with-custom-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework and Doctrine Part 1</title>
		<link>http://blog.philipbrown.id.au/2009/11/zend-framework-and-doctrine-part-1/</link>
		<comments>http://blog.philipbrown.id.au/2009/11/zend-framework-and-doctrine-part-1/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 23:24:40 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[application resource plugin]]></category>
		<category><![CDATA[application.ini]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=136</guid>
		<description><![CDATA[I&#8217;ve begun to investigate the Doctrine ORM library and how to integrate it into Zend Framework applications. I figure this post and any subsequent ones on the topic can grow into some sort of discovery series. So, my first post is going to be a simple one &#8211; bootstrapping with Doctrine 1.2. I figured the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve begun to investigate the Doctrine ORM library and how to integrate it into Zend Framework applications. I figure this post and any subsequent ones on the topic can grow into some sort of discovery series.</p>
<p>So, my first post is going to be a simple one &#8211; bootstrapping with Doctrine 1.2.</p>
<p>I figured the most robust and consistent way to get Doctrine into my applications was to create an application resource plugin so without further delay, here it is.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/Tolerable/Application/Resource/Doctrine.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Tolerable_Application_Resource_Doctrine <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Resource_ResourceAbstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * @var Doctrine_Manager
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_manager</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var Doctrine_Cache_Interface
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_cacheDriver</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string|array
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_cache</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var array
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_connections</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set cache options
     * 
     * @param string|array $cache
     * @return Tolerable_Application_Resource_Doctrine
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setCache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cache <span style="color: #339933;">=</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @return string|array
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cache<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set connection configuration
     * 
     * @param array $connections
     * @return Tolerable_Application_Resource_Doctrine
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setConnections<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$connections</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connections <span style="color: #339933;">=</span> <span style="color: #000088;">$connections</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Initialise and return Doctrine_Manager instance
     * 
     * @return Doctrine_Manager
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_manager<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$manager</span> <span style="color: #339933;">=</span> Doctrine_Manager<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>
            <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_MODEL_LOADING</span><span style="color: #339933;">,</span>
                                   Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">MODEL_LOADING_CONSERVATIVE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_VALIDATE</span><span style="color: #339933;">,</span>
                                   Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">VALIDATE_ALL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_AUTO_ACCESSOR_OVERRIDE</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_AUTOLOAD_TABLE_CLASSES</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_USE_DQL_CALLBACKS</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_AUTO_FREE_QUERY_OBJECTS</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cacheDriver</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getCacheDriver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$manager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_QUERY_CACHE</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cacheDriver</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_manager <span style="color: #339933;">=</span> <span style="color: #000088;">$manager</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_manager<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Initialise and return query cache driver if configured
     * 
     * @return Doctrine_Cache_Interface|null
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _getCacheDriver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cacheDriver<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCache</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'driver'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Resource_Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Missing Doctrine cache driver'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000088;">$driver</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'driver'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'driver'</span><span style="color: #009900;">&#93;</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;">$driver</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$options</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$driver</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$driver</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cacheDriver <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$driver</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_cacheDriver<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Initialise any configured connections
     * 
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initConnections<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connections <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dsn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'charset'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$charset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'charset'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'charset'</span><span style="color: #009900;">&#93;</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;">$charset</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'utf8'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Attempt to find &quot;dsn&quot; or &quot;connection_string&quot; keys</span>
            <span style="color: #666666; font-style: italic;">// falling back to an array of connection options</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dsn'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$adapter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dsn'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connection_string'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$adapter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'connection_string'</span><span style="color: #009900;">&#93;</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;">$adapter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$adapter</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttribute</span><span style="color: #009900;">&#40;</span>Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">ATTR_USE_NATIVE_ENUM</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCharset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$charset</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: #009933; font-style: italic;">/**
     * Initialise and return Doctrine manager
     * 
     * @return Doctrine_Manager
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_initConnections<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This class provides a reusable component to use in any ZF 1.8+ application. To enable the plugin, add the following to your <code>application.ini</code> file.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; Add the Doctrine and Tolerable namespaces to the autoloader</span>
autoloaderNamespaces<span style="">&#91;</span><span style="">&#93;</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Doctrine_&quot;</span>
autoloaderNamespaces<span style="">&#91;</span><span style="">&#93;</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Tolerable_&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; Add our custom application resource plugin path to the plugin loader</span>
pluginPaths.Tolerable_Application_Resource <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Tolerable/Application/Resource&quot;</span></pre></div></div>

<p>Configure the Doctrine query cache (if desired)</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; Simple examples, no driver options</span>
resources.doctrine.cache <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Doctrine_Cache_Apc&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; or with options</span>
resources.doctrine.cache.driver <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Doctrine_Cache_Apc&quot;</span>
resources.doctrine.cache.option <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> ...</span>
resources.doctrine.cache.option <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> ...</span>
resources.doctrine.cache.option <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> ...</span></pre></div></div>

<p>See <a href="http://www.doctrine-project.org/documentation/manual/1_0/en/caching">here</a> for drivers and options.</p>
<p>Configure the connections</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; Simple connection strings</span>
resources.doctrine.connections<span style="">&#91;</span><span style="">&#93;</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;mysql://user1:pass@localhost/db1&quot;</span>
resources.doctrine.connections<span style="">&#91;</span><span style="">&#93;</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;mysql://user2:pass@localhost/db2&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; or specify connection name and options</span>
resources.doctrine.connections.default.dsn     <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;mysql://user1:pass@localhost/db1&quot;</span>
resources.doctrine.connections.default.charset <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;utf8&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; or specify Doctrine connection parameters</span>
resources.doctrine.connections.default.scheme <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;mysql&quot;</span>
resources.doctrine.connections.default.user   <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;user1&quot;</span>
resources.doctrine.connections.default.pass   <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;pass&quot;</span>
resources.doctrine.connections.default.host   <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;localhost&quot;</span>
resources.doctrine.connections.default.path   <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;db1&quot;</span></pre></div></div>

<p>This is assuming that your custom (Tolerable in these examples) and Doctrine libraries are under your application&#8217;s &#8220;library&#8221; path. If not, simply add them to the application&#8217;s include path configuration, for example</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">includePaths.library <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/../library&quot;</span>
includePaths.doctrine <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;/path/to/doctrine/lib&quot;</span>
includePaths.custom <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;/path/to/custom/library&quot;</span></pre></div></div>

<p>A lot of the code in the plugin has been taken from Matthew Weier O&#8217;Phinney&#8217;s blog post on <a href="http://weierophinney.net/matthew/archives/220-Autoloading-Doctrine-and-Doctrine-entities-from-Zend-Framework.html">Autoloading Doctrine and Doctrine entities from Zend Framework</a>.</p>
<h3>2009-11-19 Update</h3>
<p>Some extra inspiration came from Juozas Kaziukenas&#8217; post on <a href="http://dev.juokaz.com/php/zend-framework-and-doctrine-part-2">Zend Framework and Doctrine. Part 2</a> as well as the twitter-verse and now the plugin handles multiple connections and caching.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/11/zend-framework-and-doctrine-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Overriding Zend form element default decorators, for good!</title>
		<link>http://blog.philipbrown.id.au/2009/10/overriding-zend-form-element-default-decorators-for-good/</link>
		<comments>http://blog.philipbrown.id.au/2009/10/overriding-zend-form-element-default-decorators-for-good/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 01:55:22 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[decorators]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Form_Element]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=131</guid>
		<description><![CDATA[I&#8217;m sure everybody who has used Zend_Form has, at one time or another, wished they could change the default form element decorators in one fell swoop, simply and efficiently. Up until now, I&#8217;ve been using one of two methods to override the default &#8220;definition list&#8221; style; set each element&#8217;s decorator scheme on instantiation or, use [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure everybody who has used Zend_Form has, at one time or another, wished they could change the default form element decorators in one fell swoop, simply and efficiently.</p>
<p>Up until now, I&#8217;ve been using one of two methods to override the default &#8220;definition list&#8221; style; set each element&#8217;s decorator scheme on instantiation or, use the form&#8217;s &#8220;setElementDecorators&#8221; method to reset the scheme for nominated elements. No longer!</p>
<p>Using just a few simple classes, I&#8217;ll show you how to permanently alter the default decorator scheme, thus simplifying your code and making it ultimately more flexible.</p>
<p>For the following example, I&#8217;ll assume a decorator scheme like the following</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">form
  fieldset
    ol
      li
        label
        element
      li
        button</pre></div></div>

<p>Lets start by extending Zend_Form_Element. I&#8217;d also like to take this opportunity to introduce my new &#8220;Tolerable&#8221; library.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/Tolerable/Form/Element.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Tolerable_Form_Element <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form_Element
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Load default decorators
     *
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadDefaultDecorators<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadDefaultDecoratorsIsDisabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$decorators</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decorators</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ViewHelper'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Errors'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Description'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span>
                                                     <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Label'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'requiredSuffix'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">' *'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HtmlTag'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'li'</span><span style="color: #339933;">,</span>
                                                 <span style="color: #0000ff;">'id'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'-element'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Don&#8217;t forget to add your library namespace to the auto loader</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; application/configs/application.ini</span>
&nbsp;
autoloaderNamespaces.1 <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;Tolerable_&quot;</span></pre></div></div>

<p>Zend_Form_Element_Submit also needs some treatment</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/Tolerable/Form/Element/Submit.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Tolerable_Form_Element_Submit <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form_Element_Submit
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Default decorators
     *
     * Uses only 'Submit' and 'li' decorators by default.
     * 
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadDefaultDecorators<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadDefaultDecoratorsIsDisabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$decorators</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decorators</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tooltip'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ViewHelper'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HtmlTag'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'li'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We&#8217;ll also need to provide our own display group class to support the desired scheme</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/Tolerable/Form/DisplayGroup.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Tolerable_Form_DisplayGroup <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form_DisplayGroup
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Load default decorators
     * 
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadDefaultDecorators<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadDefaultDecoratorsIsDisabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$decorators</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decorators</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Description'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'li'</span><span style="color: #339933;">,</span>
                                                     <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'group_description'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FormElements'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HtmlTag'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ol'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Fieldset'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>as well as a custom form class</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/Tolerable/Form.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Tolerable_Form <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Default display group class
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_defaultDisplayGroupClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Tolerable_Form_DisplayGroup'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Constructor
     *
     * Add custom prefix path before parent constructor
     *
     * @param mixed $options
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addPrefixPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tolerable_Form'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Tolerable/Form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Load the default decorators
     *
     * @return void
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> loadDefaultDecorators<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadDefaultDecoratorsIsDisabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$decorators</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDecorators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decorators</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FormElements'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDecorator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now that we&#8217;ve laid the way for our custom decorator scheme, there&#8217;s only one item remaining and I can&#8217;t say that I&#8217;m proud but hey, it works.</p>
<p>All front facing (HTML) Zend form elements extend the empty, abstract class Zend_Form_Element_Xhtml. We&#8217;re going to override this class in its current form. This method works well if the Zend Framework is not in the application&#8217;s &#8220;library&#8221; which should have a higher &#8220;include path&#8221; setting than the framework itself. Otherwise, you&#8217;ll just have to override the existing Zend Framework file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/Zend/Form/Element/Xhtml.php</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> Zend_Form_Element_Xhtml <span style="color: #000000; font-weight: bold;">extends</span> Tolerable_Form_Element
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it. Get ready to start writing leaner, meaner forms</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;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Tolerable_Form<span style="color: #339933;">;</span>
<span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foo'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'label'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Foo'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'textarea'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bar'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'label'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Bar'</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'submit'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'submit_btn'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'label'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Submit'</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addDisplayGroup</span><span style="color: #009900;">&#40;</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'submit_btn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'baz'</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'legend'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My Form'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/10/overriding-zend-form-element-default-decorators-for-good/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Roundcube 0.3-stable on PHPsuExec hosts</title>
		<link>http://blog.philipbrown.id.au/2009/10/roundcube-0-3-stable-on-phpsuexec-hosts/</link>
		<comments>http://blog.philipbrown.id.au/2009/10/roundcube-0-3-stable-on-phpsuexec-hosts/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 05:59:56 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[PHPRC]]></category>
		<category><![CDATA[phpSuExec]]></category>
		<category><![CDATA[Roundcube]]></category>
		<category><![CDATA[suExec]]></category>
		<category><![CDATA[suhosin]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=123</guid>
		<description><![CDATA[I&#8217;ve been using Roundcube as my webmail client since the early alpha days and was happy to see the recent release of 0.3-stable. I did have to tweak some PHP configuration items so, for the benefit of other Roundcube users, here&#8217;s how to get it up and running on a PHPsuExec enabled host. As outlined [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Roundcube as my webmail client since the early alpha days and was happy to see the recent release of 0.3-stable. I did have to tweak some PHP configuration items so, for the benefit of other Roundcube users, here&#8217;s how to get it up and running on a PHPsuExec enabled host.</p>
<p>As outlined in a <a href="http://morecowbell.net.au/2009/08/php-suexec-and-custom-php-ini-files/">previous post</a>, I created my custom configuration file under <code>/home/user/etc/php.d/roundcube/custom.ini</code> using the <code>php_flag</code> and <code>php_value</code> properties from the Roundcube <code>.htaccess</code> file.</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">display_errors</span>              <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span>
<span style="color: #000099;">log_errors</span>                  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> On</span>
<span style="color: #000099;">upload_max_filesize</span>         <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 5M</span>
<span style="color: #000099;">post_max_size</span>               <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 6M</span>
<span style="color: #000099;">memory_limit</span>                <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 64M</span>
&nbsp;
zlib.output_compression     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span>
<span style="color: #000099;">magic_quotes_gpc</span>            <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span>
zend.ze1_compatibility_mode <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span>
suhosin.session.encrypt     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span>
&nbsp;
session.auto_start          <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span>
session.gc_maxlifetime      <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 21600</span>
session.gc_divisor          <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 500</span>
session.gc_probability      <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 1</span>
&nbsp;
mbstring.func_overload      <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 0</span></pre></div></div>

<p>This file is then merged into the server configuration file as <code>/home/user/etc/php.d/roundcube/php.ini</code>.</p>
<p>Then you just need to edit the Roundcube <code>.htaccess</code> file and add</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">SetEnv PHPRC /home/user/etc/php.d/roundcube</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/10/roundcube-0-3-stable-on-phpsuexec-hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP suExec and custom php.ini files</title>
		<link>http://blog.philipbrown.id.au/2009/08/php-suexec-and-custom-php-ini-files/</link>
		<comments>http://blog.philipbrown.id.au/2009/08/php-suexec-and-custom-php-ini-files/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 00:13:59 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[PHPRC]]></category>
		<category><![CDATA[phpSuExec]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[suExec]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=107</guid>
		<description><![CDATA[Lately, I&#8217;ve noticed more and more shared web hosts making the switch to running PHP under suExec. The benefits of this are: PHP scripts run as the owning user No more file system permission juggling Scripts are generally sandboxed to the owner&#8217;s home directory Unfortunately, this poses a problem for any custom PHP configuration changes [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I&#8217;ve noticed more and more shared web hosts making the switch to running PHP under suExec. The benefits of this are:</p>
<ul>
<li>PHP scripts run as the owning user</li>
<li>No more file system permission juggling</li>
<li>Scripts are generally sandboxed to the owner&#8217;s home directory</li>
</ul>
<p>Unfortunately, this poses a problem for any custom PHP configuration changes as the usual <code>.htaccess</code> <code>php_flag</code> and <code>php_value</code> properties are no longer supported. The recommended method of setting a custom configuration is to place a <code>php.ini</code> file under each directory where required.</p>
<p>This method works fine for any properties set in the custom <code>php.ini</code> file however there appears to be one devastating omission. <em>Server configuration properties do <strong>not</strong> cascade into the custom file.</em> What this means is that for any property <em>not</em> set in your custom file, PHP will revert to the PHP default.</p>
<p>For example, say your host has enabled PDO (as any decent host should). The instant you introduce a custom <code>php.ini</code> file, PDO will be lost. Sure, you could just include the relevant <code>extension_dir</code> and <code>extension</code> properties but consider this example (from my host)</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">extension_dir</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;/usr/local/lib/php/extensions/no-debug-non-zts-20060613&quot;</span></pre></div></div>

<p>That property is awfully specific and your custom entry wouldn&#8217;t fare too well in the event of an upgrade.</p>
<p>In a perfect world, the host would have compiled PHP with the <code>--with-config-file-scan-dir=/some/dir</code> option that allows an environmentally settable directory to be scanned for additional config files. Unfortunately, this is rarely the case.</p>
<p>My solution is a little hacky and hardly perfect but it certainly gets the job done for me.</p>
<p>1. Create your custom.ini file with the options you want. Mine is <code>/home/user/etc/php.d/custom.ini</code> and looks like this</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">register_globals</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span>
<span style="color: #000099;">magic_quotes_gpc</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span></pre></div></div>

<p>Do <strong>not</strong> name this file php.ini.</p>
<p>2. Locate your host&#8217;s <code>php.ini</code> file. This information is available from <code>phpinfo()</code>. In the below examples it is <code>/usr/local/lib/php.ini</code></p>
<p>3. Add a cron job to create a full <code>php.ini</code> file in a location of your choosing (<code>/home/user/etc/php.d</code>) that is the concatenation of the server <code>php.ini</code> file and your <code>custom.ini</code> file. The below example is set to run hourly with any errors displayed on stdout which should be mailed to the crontab owner.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php.d<span style="color: #000000; font-weight: bold;">/</span>custom.ini <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php.d<span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'/usr/local/lib/php.ini NOT FOUND'</span></pre></div></div>

<p>The reason for the cron job is to keep your full, custom <code>php.ini</code> file in sync with any server changes. The job will also inform you in the unlikely event that the host <code>php.ini</code> file is moved. </p>
<p>If you&#8217;ve got shell access, you can create this file immediately by running</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php.d<span style="color: #000000; font-weight: bold;">/</span>custom.ini <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php.d<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>otherwise, wait for the hour to come around in which case your cron job should have done the work for you.</p>
<p>4. Add the following to your web application&#8217;s <code>.htaccess</code> file</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">SetEnv</span> PHPRC /home/<span style="color: #00007f;">user</span>/etc/php.d</pre></div></div>

<p>The <code>PHPRC</code> environment variable informs any PHP scripts of the location of the preferred <code>php.ini</code> file.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/08/php-suexec-and-custom-php-ini-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Editor themes for Eclipse PDT &#8211; Obsidian</title>
		<link>http://blog.philipbrown.id.au/2009/07/editor-themes-for-eclipse-pdt-obsidian/</link>
		<comments>http://blog.philipbrown.id.au/2009/07/editor-themes-for-eclipse-pdt-obsidian/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 06:01:50 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[colour themes]]></category>
		<category><![CDATA[dark]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[PDT]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=94</guid>
		<description><![CDATA[My PHP IDE of choice is Eclipse with the PDT plugin. The thing is, I always feel a little snow blind after a day&#8217;s coding, staring at that white screen all day. So much so that I&#8217;ve undertaken the arduous task of tweaking my colour preferences to match the Obsidian theme found in the more [...]]]></description>
			<content:encoded><![CDATA[<p>My PHP IDE of choice is Eclipse with the PDT plugin.</p>
<p>The thing is, I always feel a little snow blind after a day&#8217;s coding, staring at that white screen all day. So much so that I&#8217;ve undertaken the arduous task of tweaking my colour preferences to match the Obsidian theme found in the more recent versions of Notepad++. Why Eclipse can&#8217;t take some lead from Notepad++ and Aptana and make this process much easier, I don&#8217;t know but here&#8217;s the end result.</p>
<p><em>PHP file with Obsidian theme</em><br />
<a href="http://blog.philipbrown.id.au/wp-content/uploads/2009/07/eclipse-obsidian-php.png" rel="lightbox-obsidian"><img src="http://blog.philipbrown.id.au/wp-content/uploads/2009/07/eclipse-obsidian-php-300x157.png" alt="PHP file with Obsidian theme" title="PHP file with Obsidian theme" width="300" height="157" class="alignnone size-medium wp-image-97" /></a></p>
<p><em>Mixed PHP and HTML file with Obsidian theme</em><br />
<a href="http://blog.philipbrown.id.au/wp-content/uploads/2009/07/eclipse-obsidian-mixed.png" rel="lightbox-obsidian"><img src="http://blog.philipbrown.id.au/wp-content/uploads/2009/07/eclipse-obsidian-mixed-300x266.png" alt="Mixed PHP and HTML file with Obsidian theme" title="Mixed PHP and HTML file with Obsidian theme" width="300" height="266" class="alignnone size-medium wp-image-98" /></a></p>
<p>I&#8217;ve also created some preference files so you can play along at home. Please note that whilst I&#8217;ve made sure the preference files only contain colour data, I&#8217;ve only done minor testing but so far, everything has gone well. My setup is Eclipse Galileo with PDT 2.1 however I don&#8217;t think there&#8217;s any version specific stuff in the files.</p>
<p>To install the colour preferences:</p>
<ol>
<li>Download one of the below packages and extract the contents to a temporary directory</li>
<li>Fire up Eclipse</li>
<li>Backup your current preferences by going to <code>File -> Export -> General -> Preferences</code>. Follow the instructions from there to create a preferences file. Make sure you choose &#8220;Export all&#8221;.</li>
<li>Go to <code>File -> Import -> General -> Preferences</code> and select the <code>Obsidian/eclipse.epf</code> file. Click &#8220;Finish&#8221;</li>
</ol>
<p>I&#8217;ve also included some Aptana colourisation files for CSS and JavaScript however I haven&#8217;t yet created preferences for other Aptana editors.</p>
<p>Enjoy and keep watching for more themes.</p>
<p><a href='http://blog.philipbrown.id.au/wp-content/uploads/2009/07/Obsidian.tar.gz'>Obsidian.tar.gz</a><br />
<a href='http://blog.philipbrown.id.au/wp-content/uploads/2009/07/Obsidian.zip'>Obsidian.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/07/editor-themes-for-eclipse-pdt-obsidian/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Extending Zend Framework Application Resource Plugins</title>
		<link>http://blog.philipbrown.id.au/2009/06/extending-zend-framework-application-resource-plugins/</link>
		<comments>http://blog.philipbrown.id.au/2009/06/extending-zend-framework-application-resource-plugins/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 01:21:50 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[bootstrap]]></category>
		<category><![CDATA[resource plugins]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=89</guid>
		<description><![CDATA[With the arrival of Zend Framework version 1.8 came the application resource plugins. These nifty little classes help bootstrap your application&#8217;s resources (views, layouts, database connections, etc). The default behaviour is suitable for most needs however, occasionally, you&#8217;re going to want to perform some extra functionality. Take for example the following use case &#8211; the [...]]]></description>
			<content:encoded><![CDATA[<p>With the arrival of Zend Framework version 1.8 came the application resource plugins. These nifty little classes help bootstrap your application&#8217;s resources (views, layouts, database connections, etc). The default behaviour is suitable for most needs however, occasionally, you&#8217;re going to want to perform some extra functionality.</p>
<p>Take for example the following use case &#8211; the standard DB resource plugin instantiates a database connection based on supplied parameters and registers it with <code>Zend_Db_Table_Abstract::setDefaultAdapter()</code>. What if you want to register the connection in the <code>Zend_Registry</code> as well? You could create a bootstrap method (<code>_initRegistry()</code> for example) and pull the adapter out of <code>Zend_Db_Table_Abstract</code> <em>or</em> you could simply extend the resource plugin.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// library/My/Application/Resource/Db.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> My_Application_Resource_Db <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Resource_Db
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDbAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dbAdapter'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This class simply adds the created database adapter to the registry before continuing on with the default behaviour.</p>
<p>To let the application know about your custom plugin, you simply add the plugin path to your <code>application.ini</code> file, eg</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">includePaths.library <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/../library&quot;</span>
pluginPaths.My_Application_Resource <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;My/Application/Resource&quot;</span></pre></div></div>

<p>More reading is available here &#8211; <a href="http://framework.zend.com/manual/en/zend.application.theory-of-operation.html">http://framework.zend.com/manual/en/zend.application.theory-of-operation.html</a></p>
<p>Further examples here &#8211; <a href="http://framework.zend.com/manual/en/zend.application.examples.html">http://framework.zend.com/manual/en/zend.application.examples.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/06/extending-zend-framework-application-resource-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internet Explorer Application Compatibility VPC Images under VirtualBox</title>
		<link>http://blog.philipbrown.id.au/2009/03/internet-explorer-application-compatibility-vpc-images-under-virtualbox/</link>
		<comments>http://blog.philipbrown.id.au/2009/03/internet-explorer-application-compatibility-vpc-images-under-virtualbox/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 04:24:43 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[VPC Image]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=73</guid>
		<description><![CDATA[With the release of Internet Explorer version 8, Microsoft have added yet another browser into the mix for we web developers to support. Testing on different versions of Internet Explorer has always presented some challenges. Unlike some other browsers, it&#8217;s not possible to truly run various versions side-by-side. Some applications like Tredosoft&#8217;s Multiple IEs go [...]]]></description>
			<content:encoded><![CDATA[<p>With the release of Internet Explorer version 8, Microsoft have added yet another browser into the mix for we web developers to support.</p>
<p>Testing on different versions of Internet Explorer has always presented some challenges. Unlike some other browsers, it&#8217;s not possible to <em>truly</em> run various versions side-by-side. Some applications like <a href="http://tredosoft.com/Multiple_IE">Tredosoft&#8217;s Multiple IEs</a> go some way to providing this functionality however problems still manage to present themselves.</p>
<p>The easiest way to really test is to use virtual machines created with specific versions of Internet Explorer running under Windows XP or Vista. Microsoft have kindly donated free, <a href="http://www.microsoft.com/Downloads/details.aspx?FamilyID=21eabb90-958f-4b64-b5f1-73d0a413c8ef&#038;displaylang=en">downloadable disk images</a> to run under their <a href="http://www.microsoft.com/Windows/products/winfamily/virtualpc/default.mspx">Virtual PC</a> software.</p>
<p>Unfortunately for some, Virtual PC only runs under Windows. I prefer <a href="http://www.virtualbox.org/">Sun&#8217;s alternative</a> so here are some instructions for installing the Internet Explorer Application Compatibility VPC Images under VirtualBox:</p>
<ol>
<li>Go <a href="http://www.microsoft.com/Downloads/details.aspx?FamilyID=21eabb90-958f-4b64-b5f1-73d0a413c8ef&#038;displaylang=en">here</a> and download the VPC disk image(s) of your choice.</li>
<li>Extract the VHD file using your favourite archive manager. You should probably read the associated documentation and EULA.</li>
<li>Start VirtualBox and hit &#8220;New&#8221;.</li>
<li>Choose the appropriate operating system and give your new VM a name and some RAM.</li>
<li>On the hard disk screen, click &#8220;Existing&#8221; to open the Virtual Media Manager.</li>
<li>Click &#8220;Add&#8221; and locate the extracted VHD file.</li>
<li>Select the new disk image and click &#8220;Ok&#8221;, &#8220;Next&#8221; then &#8220;Finish&#8221;</li>
<li>Start up the VM and press F8 as it boots to get into the Windows startup menu. If you don&#8217;t make it here on the first try, just wait for the BSOD then try again.</li>
<li>Start Windows in Safe Mode. It may take a little while for your peripherals to start responding, just be patient.</li>
<li>Ignore any new hardware wizards and open up a command prompt. Run<br />
<code>sc config Processor start= disabled</code><br />
Now reboot.
</li>
<li>Again, ignore any new hardware wizards and select Devices -> Install Guest Additions. Follow the installation prompts and reboot.</li>
<li>Once more, ignore the hardware wizards and open a command prompt. The guest additions ISO should still be mounted at D:. Run<br />
<code>D:\VBoxWindowsAdditions-x86 /extract /D=C:\Drivers</code>
</li>
<li>Now go through the new hardware wizards. For the Ethernet controller, point the wizard at <code>C:\Drivers\x86\Network\AMD</code></li>
</ol>
<p>That should be it. I&#8217;ve tested this using the Windows XP images and all has gone well.</p>
<p>Unfortunately, it looks like Microsoft have used the same disk UUID for each image which means VirtualBox will only allow one image at a time into the Virtual Media Manager. Hopefully <a href="http://www.virtualbox.org/ticket/3443">this bug</a> will be fixed shortly which should clear things up.</p>
<h3>UPDATE</h3>
<p>If you see a dialog on startup looking for cmBatt.sys and you don&#8217;t have a Windows CD handy, just disable the unknown battery device from Device Manager.</p>
<h3>UPDATE 2009-05-21</h3>
<p>Looks like the aforementioned <a href="http://www.virtualbox.org/ticket/3443">UUID bug</a> may be addressed in the next VBox release (2.2.3). All I can say is &#8220;thanks VirtualBox team, love your work&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/03/internet-explorer-application-compatibility-vpc-images-under-virtualbox/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
