<?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>Wed, 13 Jan 2010 02:14:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend Framework 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 most robust [...]]]></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>
    protected <span style="color: #000088;">$_manager</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var Doctrine_Cache_Interface
     */</span>
    protected <span style="color: #000088;">$_cacheDriver</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var string|array
     */</span>
    protected <span style="color: #000088;">$_cache</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var array
     */</span>
    protected <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>
    protected <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>
                    throw <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>
    protected <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 the [...]]]></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>
    protected <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>3</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 in [...]]]></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 as the usual .htaccess [...]]]></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 recent [...]]]></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://morecowbell.net.au/wp-content/uploads/2009/07/eclipse-obsidian-php.png" rel="lightbox-obsidian"><img src="http://morecowbell.net.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://morecowbell.net.au/wp-content/uploads/2009/07/eclipse-obsidian-mixed.png" rel="lightbox-obsidian"><img src="http://morecowbell.net.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://morecowbell.net.au/wp-content/uploads/2009/07/Obsidian.tar.gz'>Obsidian.tar.gz</a><br />
<a href='http://morecowbell.net.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>13</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 standard [...]]]></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>Boxen &#8211; a jQuery iframe plugin</title>
		<link>http://blog.philipbrown.id.au/2009/04/boxen-a-jquery-iframe-plugin/</link>
		<comments>http://blog.philipbrown.id.au/2009/04/boxen-a-jquery-iframe-plugin/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 01:00:41 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[Lightbox]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=60</guid>
		<description><![CDATA[As mentioned in a previous post, I&#8217;m a big fan of displaying small, configuration style screens in Lightbox style windows. If you&#8217;re not familiar with Lightbox, check it out here.
The thing with configuration screens is they usually have a little more to do than simply display an image or other static content. In fact,  [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned in a <a href="http://morecowbell.net.au/2009/02/changing-layouts-with-zend-contextswitch/">previous post</a>, I&#8217;m a big fan of displaying small, configuration style screens in Lightbox style windows. If you&#8217;re not familiar with Lightbox, check it out <a href="http://www.lokeshdhakar.com/projects/lightbox2/" title="Lightbox">here</a>.</p>
<p>The thing with configuration screens is they usually have a little more to do than simply display an image or other static content. In fact,  most of the ones I&#8217;ve written require some sort of AJAX functionality. Using an <code>iframe</code> is perfect for these scenarios as they operate as a self contained window, complete with any custom JavaScript.</p>
<p>I began using Cody Lindley&#8217;s <a href="http://jquery.com/demo/thickbox/" title="ThickBox">ThickBox</a> and more recently <a href="http://swip.codylindley.com/DOMWindowDemo.html" title="DOMWindow">DOMWindow</a> to load my iframes dynamically. Whist both of these plugins are great, I found they lacked the ability to truly style the boxes and extending them to add callbacks and extra features was not possible without editing the core JavaScript. I was after a simple yet expandable solution to dynamically open an iframe in a Lightbox style window.</p>
<h3>Boxen</h3>
<p>The boxen plugin allows you to bind a click event to any element that will open a Lightbox style iframe.</p>
<h4>Example</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.boxen'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">boxen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#boxen_google'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">boxen</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://www.google.com/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#boxen_search'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">boxen</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://www.google.com/search'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        urlParams<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            q<span style="color: #339933;">:</span> <span style="color: #3366CC;">'More Cowbell'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Documentation</h4>
<p><code>boxen([url or options], [options])</code></p>
<h5>Arguments</h5>
<p><code>url or options</code> (optional) &#8211; <a href="http://docs.jquery.com/Types#String">String</a>, <a href="http://docs.jquery.com/Types#Options">Options</a></p>
<blockquote><p>If the first parameter is a string, it is used as the URL for the iframe source. Otherwise, it is treated as the options map.</p></blockquote>
<p><code>options</code> (optional) &#8211; <a href="http://docs.jquery.com/Types#Options">Options</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">urlParams<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
showTitleBar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
showCloseButton<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
title<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span>
titleAttribute<span style="color: #339933;">:</span> <span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</span>
closeButtonText<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span>
width<span style="color: #339933;">:</span> <span style="color: #CC0000;">600</span><span style="color: #339933;">,</span>
height<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
url<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span>
urlAttribute<span style="color: #339933;">:</span> <span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span>
overlayOpacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.8</span><span style="color: #339933;">,</span>
overlayColor<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span>
modal<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
postOpen<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>contentAreaElement<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
postClose<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: #009900;">&#125;</span></pre></div></div>

<h4>Demo</h4>
<p><a href="http://morecowbell.net.au/demos/plugins/boxen/">Boxen Demo</a></p>
<h4>Download</h4>
<ul>
<li><a href='http://morecowbell.net.au/wp-content/uploads/2009/04/Boxen-1.4.tar.gz'>Boxen-1.4.tar.gz</a> (13k)</li>
<li><a href='http://morecowbell.net.au/wp-content/uploads/2009/04/Boxen-1.4.zip'>Boxen-1.4.zip</a> (14k)</li>
</ul>
<h3>UPDATE 2009-03-20</h3>
<p>Boxen now has the ability to open an empty canvas. Simply cancel out any URL by setting the <code>url</code> or <code>urlAttribute</code> options to <code>null</code>. See the demo page for a nifty Google Maps example.</p>
<h3>UPDATE 2009-04-06</h3>
<p>Boxen 1.2 is now IE6 compatible. Due to the lack of <code>position: fixed</code>, the experience may be a little jerky / flickery when the window is resized and occasionally the transparent overlay may be a few pixels too long or too short however I think this is a case of &#8220;near enough is good enough&#8221;.</p>
<p>Unfortunately, I&#8217;ve had to alter the Boxen &#8220;id&#8221; attribute naming convention and remove the leading underscore to get it to work in IE6. If you&#8217;ve used any custom CSS rules, you&#8217;ll need to edit them accordingly.</p>
<p>Also fixed in this version:</p>
<ul>
<li>BIG iFrame implementation for overlaying IE6 form controls</li>
<li>Safari iFrame ID caching bug</li>
<li>Opera opacity issue</li>
</ul>
<p>I&#8217;ve only tested this using a STRICT doctype and encourage everyone else to do so too.</p>
<h3>UPDATE 2009-10-08</h3>
<p>Boxen 1.3 contains the following updates:</p>
<ul>
<li>Fixed &#8220;frameBorder&#8221; case sensitivity (thanks Caleb)</li>
<li>Added more streamlined way to anonymously open a Boxen window

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">Boxen</span>.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span><span style="color: #3366CC;">'http://www.google.com/'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Boxen window title'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Now released under the MIT license</li>
</ul>
<h3>UPDATE 2009-11-30</h3>
<p>Boxen 1.4 contains the following updates</p>
<ul>
<li>Added &#8220;overlayColor&#8221; option</li>
<li>Stylesheet example now includes a &#8220;spinner&#8221; loading animation (courtesy of http://www.ajaxload.info/). Provided your iFrame / content specifies a background, the spinner will not be visible once the content loads</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/04/boxen-a-jquery-iframe-plugin/feed/</wfw:commentRss>
		<slash:comments>35</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 some [...]]]></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>8</slash:comments>
		</item>
		<item>
		<title>Changing layouts with Zend ContextSwitch</title>
		<link>http://blog.philipbrown.id.au/2009/02/changing-layouts-with-zend-contextswitch/</link>
		<comments>http://blog.philipbrown.id.au/2009/02/changing-layouts-with-zend-contextswitch/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 03:19:58 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Context Switch]]></category>
		<category><![CDATA[layout]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=51</guid>
		<description><![CDATA[Ever since discovering Zend Framework&#8217;s ContextSwitch and AjaxContext action helpers, I&#8217;ve been hooked. What&#8217;s not to love about writing one controller action and having the request dictate the response format.
Whilst this generally does the job for XML, JSON and AJAX HTML snippets where any layout is disabled, sometimes you just need to wrap that content [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since discovering Zend Framework&#8217;s <a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch">ContextSwitch and AjaxContext</a> action helpers, I&#8217;ve been hooked. What&#8217;s not to love about writing one controller action and having the request dictate the response format.</p>
<p>Whilst this generally does the job for XML, JSON and AJAX HTML snippets where any layout is disabled, sometimes you just need to wrap that content in <em>something</em>.</p>
<p>I often find myself writing small configuration screens that work nicely in modal style dialogs as opposed to a devoted web page. Generally I&#8217;ll render these screens as inline frames using my favourite <a href="http://jquery.com/">JavaScript library</a> and <a href="http://swip.codylindley.com/DOMWindowDemo.html">DOM Window</a> (a <a href="http://jquery.com/demo/thickbox/">ThickBox</a> successor). The problem with iframes is they require a complete HTML document. ContextSwitch just wasn&#8217;t cutting it as I needed some kind of layout but obviously not the full blown, menus and all default.</p>
<p>The solution was to implement my own custom context, complete with a post-processing callback function to alter the layout script. Here&#8217;s how I&#8217;ve done it.</p>
<p>First, I added a static method to my Bootstrap class to add a suffix to the layout script name should a context be present.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> setLayoutContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$layout</span> <span style="color: #339933;">=</span> Zend_Layout<span style="color: #339933;">::</span><span style="color: #004000;">getMvcInstance</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: #009900; font-weight: bold;">null</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$layout</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isEnabled</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: #000088;">$context</span> <span style="color: #339933;">=</span> Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">getStaticHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ContextSwitch'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCurrentContext</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: #009900; font-weight: bold;">null</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$context</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>For example, given the default layout script <code>layout.phtml</code> and context <code>iframe</code>, this method will set the layout script to <code>layout.iframe.phtml</code></p>
<p>Now I just need to add the context to the action helper. Again, in my Bootstrap class.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> setupActionHelpers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// This method is called during application bootstrapping</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Add &quot;iframe&quot; context</span>
    <span style="color: #000088;">$iframeContext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'suffix'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'iframe'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'callbacks'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'post'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'setLayoutContext'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$contextSwitch</span> <span style="color: #339933;">=</span> Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">getStaticHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ContextSwitch'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$contextSwitch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addContext</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'iframe'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iframeContext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ok, that&#8217;s all the preparation work out of the way. To add this context to a controller action, you simply, well, add it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<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: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">contextSwitch</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addActionContext</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iframe'</span><span style="color: #009900;">&#41;</span>
                                     <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAutoDisableLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</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>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Controller tasks here</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>All that&#8217;s left to do is ensure your links to the context enabled controller action include the correct <code>format</code> parameter, for example <code>/my/config/format/iframe</code> or <code>/my/config?format=iframe</code>.</p>
<p>One thing I&#8217;ve noticed is that the ContextSwitch helper should be configured <em>after</em> your view and layout are initialised.</p>
<p>Thanks to Jeff Carouth for the <a href="http://carouth.com/blog/focus/context-switching-layouts-with-the-zend-framework--26">inspiration</a> for this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2009/02/changing-layouts-with-zend-contextswitch/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jQuery AJAX Autocomplete with JSON data</title>
		<link>http://blog.philipbrown.id.au/2008/10/jquery-ajax-autocomplete-with-json-data/</link>
		<comments>http://blog.philipbrown.id.au/2008/10/jquery-ajax-autocomplete-with-json-data/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 00:57:58 +0000</pubDate>
		<dc:creator>Phil</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://morecowbell.net.au/?p=33</guid>
		<description><![CDATA[I recently had a requirement to implement an auto-complete input box in a dynamic form. Since I was already using jQuery, I had a look at the available plugins.
After sorting through a few, I decided on this one from Jörn Zaefferer. The only problem was, I wanted to use the wonderfully simple Zend Framework AjaxContext [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a requirement to implement an auto-complete input box in a dynamic form. Since I was already using jQuery, I had a look at the available plugins.</p>
<p>After sorting through a few, I decided on <a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/">this one from Jörn Zaefferer</a>. The only problem was, I wanted to use the wonderfully simple <a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch">Zend Framework AjaxContext Action Helper</a> to produce JSON data as my auto-complete data source. I like JSON as it&#8217;s easy to produce and easy to deal with in disparate systems (such as PHP and JavaScript). Unfortunately, Jörn&#8217;s plugin is built to work with a simple, formatted ASCII list delimited by newlines. Fortunately, he also put a lot of work into this plugin, he just hasn&#8217;t gotten around to documenting it all yet.</p>
<p>For this post, I&#8217;ll assume my AJAX request is for some user data out of LDAP (or a similar data store) and resembles this</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;users&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;uid&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;123&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;displayName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;User 123&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;mail&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;123@example.com&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;uid&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;456&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;displayName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;User 456&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;mail&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;456@example.com&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;uid&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;789&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;displayName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;User 789&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;mail&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;789@example.com&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>The secret to extending the Autocomplete plugin is the ability to overwrite certain core functions, primarily <code>parse</code>. The internal version of this function simply loops over each line of the returned data and &#8220;parses&#8221; it into an array of objects, each containing the following attributes:</p>
<ul>
<li><code>data</code> &#8211; the entire entry</li>
<li><code>value</code> &#8211; the default display value</li>
<li><code>result</code> &#8211; the data to populate the input element on selection</li>
</ul>
<p>You can overwrite this by passing your own <code>parse</code> function as part of the options object to <code>autocomplete</code>. Mine also includes a custom <code>formatItem</code> function for displaying each entry.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> acOptions <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    minChars<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
    max<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span>
    dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// this parameter is currently unused</span>
    extraParams<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        format<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span> <span style="color: #006600; font-style: italic;">// pass the required context to the Zend Controller</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    parse<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>
        <span style="color: #003366; font-weight: bold;">var</span> parsed <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        data <span style="color: #339933;">=</span> data.<span style="color: #660066;">users</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> data.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            parsed<span style="color: #009900;">&#91;</span>parsed.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                data<span style="color: #339933;">:</span> data<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                value<span style="color: #339933;">:</span> data<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">displayName</span><span style="color: #339933;">,</span>
                result<span style="color: #339933;">:</span> data<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">displayName</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">return</span> parsed<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    formatItem<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">displayName</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' ('</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">mail</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The autocomplete plugin will now accept and parse JSON data.</p>
<p>Another thing I wanted to do with this page was to show one value but use another. In this case, I only want to display the user names and email addresses and use the UID without displaying it or putting it into the form field. This is where having each item available as a JSON object comes in very handy.</p>
<p>For this trick, I&#8217;ll add a hidden input field and place the UID into that when an item is selected. Here&#8217;s my form field</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_id&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;user_id&quot;</span>&gt;</span></pre></div></div>

<p>and here&#8217;s the JavaScript</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// autocomplete options as above</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><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;">'#user_id'</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/path/to/ajax/data/source'</span><span style="color: #339933;">,</span> acOptions<span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'display_name'</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input type=&quot;hidden&quot; name=&quot;user_id&quot; id=&quot;ac_result&quot;&gt;'</span><span style="color: #009900;">&#41;</span>
        .<span style="color: #660066;">result</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ac_result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">uid</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>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The reason I changed the <code>name</code> attribute of the original input and gave it to the new hidden one is so I can still submit the form normally and work with the submitted &#8220;user_id&#8221; value.</p>
<p>The Autocomplete <code>result</code> function receives the selected item&#8217;s <code>data</code> property when an item is selected. With the above configuration, this is the actual JSON object</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.philipbrown.id.au/2008/10/jquery-ajax-autocomplete-with-json-data/feed/</wfw:commentRss>
		<slash:comments>6</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! -->