<?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>vandenbos.org</title>
	<atom:link href="http://blog.vandenbos.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vandenbos.org</link>
	<description>Matthijs van den Bos&#039; thoughts on web development topics</description>
	<lastBuildDate>Mon, 08 Feb 2010 08:11:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Been offline for two weeks&#8230;</title>
		<link>http://blog.vandenbos.org/2010/02/08/been-offline-for-two-weeks/</link>
		<comments>http://blog.vandenbos.org/2010/02/08/been-offline-for-two-weeks/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 08:11:47 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=184</guid>
		<description><![CDATA[&#8230;and I didn&#8217;t even notice it. That shows that I&#8217;m too busy with other things like finishing my book and finishing a project at work. Both will be done somewhere in march, so you can expect a new post around that time. 
Apart from a new post, I will be paying attention to an older [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;and I didn&#8217;t even notice it. That shows that I&#8217;m too busy with other things like finishing my book and finishing a project at work. Both will be done somewhere in march, so you can expect a new post around that time. </p>
<p>Apart from a new post, I will be paying attention to an older article on this blog about module configuration in Zend Framework. It is still a hot subject, and I have gotten some good questions and remarks from many commenters. I will answer all these questions, show more source code as requested and maybe I&#8217;ll even listen to some suggestions. <img src='http://blog.vandenbos.org/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2010/02/08/been-offline-for-two-weeks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZF: assigning objects to partials the easy way</title>
		<link>http://blog.vandenbos.org/2009/10/20/zf-assigning-objects-to-partials/</link>
		<comments>http://blog.vandenbos.org/2009/10/20/zf-assigning-objects-to-partials/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 20:16:55 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[partials]]></category>
		<category><![CDATA[Zend_View_Helper_Partial]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=176</guid>
		<description><![CDATA[Recently, I have been using view script partials (Zend_View_Helper_Partial) and wanted to assign an object as an object to a partial and have full use of it in the partial. I found the solution in the ZF manual very impractical and thought of another way to solve this. In this post I describe the &#8216;ZF [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I have been using view script partials (Zend_View_Helper_Partial) and wanted to assign an object <em>as an object</em> to a partial and have full use of it in the partial. I found the solution in the ZF manual very impractical and thought of another way to solve this. In this post I describe the &#8216;ZF manual&#8217; way to do it, and my easier way.</p>
<p><span id="more-176"></span></p>
<p>The object I wanted to assign was an instance of Zend Form assigned to the view on the key &#8216;commentForm&#8217;. Of course without reading the documentation, this is what I put in the view script where I wanted to include the partial:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">partial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blogpost/new-comment.phtml'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">commentForm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This didn&#8217;t work, as I found out that the object contained in $this-commentForm was converted to array and assigned as properties to the view instance of the partial. This is done either by calling toArray() on the object if the method exists, or by using get_object_vars on the object. </p>
<p>This is not what I wanted. I wanted to have full use of my form object in my partial. When I finally did read the manual entry about partials, I found that there was actually a way to do this, but not a very practical way. You call the method setObjectKey(&#8216;keyname&#8217;) on the partial helper like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">partial</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setObjectKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'commentForm'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you do this first and then assign an object to a partial as above, the object gets assigned to the view instance of the partial on the key we set with setObjectKey(). Thus, we have full use of the object in the partial.</p>
<p>There are a couple of drawbacks to this way of doing it. First, it is irritating that I have to call setObjectKey() every time I want to do this. Second, the view script becomes less readable if I have to include this kind of code. Third, but I have yet to test this, it seems to me that the object key is set for <strong>all</strong> partials when you use setObjectKey(). This may have some unwanted side effects if you are not careful.</p>
<p>Here is my solution to this &#8216;problem&#8217;. In my eyes, it makes setObjectKey obsolete. Why not just assign an array to the partial, containing my form object like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">partial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'blogpost/new-comment.phtml'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'commentForm'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">commentForm</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>I know, it is too simple. So simple even, that I overlooked this possibility at first. And the manual doesn&#8217;t help. The result is that I have found many posts on blogs and forums about this problem and the usage of setObjectKey(). I hope this post will be helpful to some of them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/10/20/zf-assigning-objects-to-partials/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Zend Framework: module specific frontcontroller plugins</title>
		<link>http://blog.vandenbos.org/2009/09/03/zend-framework-module-specific-frontcontroller-plugins/</link>
		<comments>http://blog.vandenbos.org/2009/09/03/zend-framework-module-specific-frontcontroller-plugins/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 11:33:08 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[frontcontroller]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[Zend_Application]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=158</guid>
		<description><![CDATA[Here is another situation I have run into while trying to build a modular application: sometimes you need to run a frontcontroller plugin ONLY when a specific module is requested. An example could be authentication. Say I have a public site and an admin section. The most obvious solution is to enable the authentication plugin [...]]]></description>
			<content:encoded><![CDATA[<p>Here is another situation I have run into while trying to build a modular application: sometimes you need to run a frontcontroller plugin ONLY when a specific module is requested. An example could be authentication. Say I have a public site and an admin section. The most obvious solution is to enable the authentication plugin only when the admin section is requested. This is something that is not possible with Zend_Application and the frontcontroller resource. So, as I did for <a href="http://blog.vandenbos.org/2009/07/19/zend-framework-module-specific-layout/">loading module specific layouts</a>, I wrote a frontcontroller plugin for registering module specific frontcontroller plugins: the Rexus_Controller_Plugin_RequestedModulePluginLoader. It works together with a Zend_Application resource called Rexus_Application_Resource_Moduleplugins. Let&#8217;s get started.</p>
<p><span id="more-158"></span></p>
<h2>Usage Example</h2>
<p>
First we load the frontcontroller plugin Rexus_Controller_Plugin_RequestedModulePluginLoader in the main application.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>frontController<span style="color: #339933;">.</span>plugins<span style="color: #339933;">.</span>pluginloader <span style="color: #339933;">=</span> Rexus_Controller_Plugin_RequestedModulePluginLoader<span style="color: #339933;">;</span></pre></div></div>

<p>Then we use the Zend_Application resource Rexus_Application_Resource_Moduleplugins in our config file to load the the authentication plugin only for our module.<br />
If you use my ModuleSetup resource as described in <a href="http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/">module config</a>, you can set the module plugin options in the module.ini for that module :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>moduleplugins<span style="color: #339933;">.</span>auth <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Rexus_Controller_Plugin_Authentication&quot;</span></pre></div></div>

<p>or, you can set the module plugins config in your application.ini normally, as described in the Zend Framework reference:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">modulename<span style="color: #339933;">.</span>resources<span style="color: #339933;">.</span>moduleplugins<span style="color: #339933;">.</span>auth <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Rexus_Controller_Plugin_Authentication&quot;</span></pre></div></div>

<p>The result is that the frontcontroller plugin Rexus_Controller_Plugin_Authentication is only loaded if the module &#8216;modulename&#8217; is requested.</p>
<h2>Code</h2>
<p></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Rexus_Controller_Plugin_RequestedModulePluginLoader 
    <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Plugin_Abstract
<span style="color: #009900;">&#123;</span>
    protected <span style="color: #000088;">$_modulePlugins</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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> registerFrontControllerPlugin<span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pluginName</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: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_modulePlugins<span style="color: #009900;">&#41;</span> 
                        <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_modulePlugins<span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_modulePlugins<span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pluginName</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;">$this</span><span style="color: #339933;">-&gt;</span>_modulePlugins<span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pluginName</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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> routeShutdown<span style="color: #009900;">&#40;</span>Zend_Controller_Request_Abstract <span style="color: #000088;">$request</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_modulePlugins<span style="color: #009900;">&#91;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$frontController</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_modulePlugins<span style="color: #009900;">&#91;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$pluginName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$frontController</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerPlugin</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$pluginName</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>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Just drop this class in your library and register the plugin with the frontcontroller as shown above to use it.</p>
<p>Note that this plugin does its work on routeShutdown. On routShutDown is the earliest hook in the dispatch loop where the request has been parsed and routed. This is important because all plugins we register with this plugin can subsequently only be registered with the frontcontroller as early as the next step after the one on which this plugin is executed. </p>
<p>Next we need the code for the Zend_Application resource Rexus_Application_Resource_Moduleplugins:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Rexus_Application_Resource_Moduleplugins 
    <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Resource_ResourceAbstract
<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;">$bootstrap</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$bootstrap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frontcontroller'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bootstrap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frontcontroller'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$pluginLoader</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPlugin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Rexus_Controller_Plugin_RequestedModulePluginLoader'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$pluginName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$pluginLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerFrontControllerPlugin</span><span style="color: #009900;">&#40;</span>
                <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pluginName</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>

]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/09/03/zend-framework-module-specific-frontcontroller-plugins/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Writing a book about Zend Framework</title>
		<link>http://blog.vandenbos.org/2009/09/03/writing-a-book-about-zend-framework/</link>
		<comments>http://blog.vandenbos.org/2009/09/03/writing-a-book-about-zend-framework/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 10:53:37 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[book]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=155</guid>
		<description><![CDATA[I have been busy with this project for some time, but now I feel that I really have something to say: I have started writing a book about Zend Framework. Yay! Sadly, for all you non Dutch-speaking readers, the book is aimed at the Dutch market and will be written in Dutch. I am writing [...]]]></description>
			<content:encoded><![CDATA[<p>I have been busy with this project for some time, but now I feel that I really have something to say: I have started writing a book about Zend Framework. Yay! Sadly, for all you non Dutch-speaking readers, the book is aimed at the Dutch market and will be written in Dutch. I am writing the book together with a co-writer, named <a href="http://www.themotionstudio.nl/" target="_blank">Wouter Tengeler</a>. He has written two (Dutch) PHP books before. The book will be published by <a href="http://www.vanduurenmedia.nl/" target="_blank">Van Duuren Media</a>, a small publisher specialized in technical and management books. It will be part of the series &#8216;Leer jezelf PROFESSIONEEL&#8230;&#8217;. The expected publish date will be in the first half of next year.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/09/03/writing-a-book-about-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some personal news: new job @ Ibuildings</title>
		<link>http://blog.vandenbos.org/2009/09/03/some-personal-news-new-job-ibuildings/</link>
		<comments>http://blog.vandenbos.org/2009/09/03/some-personal-news-new-job-ibuildings/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 10:43:50 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[ibuildings]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=152</guid>
		<description><![CDATA[Well, I&#8217;m back. I&#8217;ve been away on holiday and I have been busy talking to some possible new employers. But then I found out that Ibuildings was looking for a senior software engineer. Ibuildings is the leading PHP authority in the UK and The Netherlands, and is the representative of Zend Technologies in these countries. [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I&#8217;m back. I&#8217;ve been away on holiday and I have been busy talking to some possible new employers. But then I found out that <a href="http://www.ibuildings.co.uk/" target="_blank">Ibuildings</a> was looking for a senior software engineer. Ibuildings is the leading PHP authority in the UK and The Netherlands, and is the representative of Zend Technologies in these countries. I&#8217;ve had my eye on them for a few years now, because their philosophy about the role of PHP directly mirrors my own. Also, they play an active role in the PHP-community and have a couple of very talented people working for them. I find that an inspiring environment, so I jumped on the opportunity and sent them an e-mail. Well, to make a long story short, I got the job and I am very happy to start at the Utrecht location in the Netherlands on October 2nd!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/09/03/some-personal-news-new-job-ibuildings/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Zend Framework: htaccess url rewrite infinite loop</title>
		<link>http://blog.vandenbos.org/2009/07/22/zend-framework-htaccess-url-rewrite-infinite-loop/</link>
		<comments>http://blog.vandenbos.org/2009/07/22/zend-framework-htaccess-url-rewrite-infinite-loop/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:59:42 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[zend_tool]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=136</guid>
		<description><![CDATA[Just a short one this time. This is something I encountered at work today.
I started a new ZF project in our development environment, which makes use of dynamic virtualhosts.
When I started the application for the first time in the browser, I got an internal server error.
Of course I didn&#8217;t expect this. So I had a [...]]]></description>
			<content:encoded><![CDATA[<p>Just a short one this time. This is something I encountered at work today.<br />
I started a new ZF project in our development environment, which makes use of dynamic virtualhosts.<br />
When I started the application for the first time in the browser, I got an internal server error.</p>
<p>Of course I didn&#8217;t expect this. So I had a look at the apache logs and found entries like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>Wed Jul <span style="color: #cc66cc;">22</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">:</span><span style="color: #208080;">00</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">26</span> <span style="color: #cc66cc;">2009</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#91;</span>debug<span style="color: #009900;">&#93;</span> core<span style="color: #339933;">.</span>c<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3052</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>client 192<span style="color: #339933;">.</span>168<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>7<span style="color: #009900;">&#93;</span> redirected from r<span style="color: #339933;">-&gt;</span><span style="color: #004000;">uri</span> <span style="color: #339933;">=</span> <span style="color: #339933;">/</span>data<span style="color: #339933;">/</span>virtualhosts<span style="color: #339933;">/</span>dev<span style="color: #339933;">/...</span></pre></div></div>

<p>After some googling, I found out this has something to do with having apache rewrite rules in combination with dynamic virtualhosts. Then I had a look at an older ZF project on the same server and found a small but significant difference:</p>
<p>Standard .htaccess created by Zend_Tool:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">SetEnv</span> APPLICATION_ENV development
&nbsp;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -s [OR]
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -l [OR]
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} -d
<span style="color: #00007f;">RewriteRule</span> ^.*$ - [NC,L]
<span style="color: #00007f;">RewriteRule</span> ^.*$ index.php [NC,L]</pre></div></div>

<p>And here is the last line of the older .htaccess, the rest is identical:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteRule</span> ^.*$ /index.php [NC,L]</pre></div></div>

<p>Notice the difference? There is a forward slash before index.php in the working .htaccess.<br />
I simply added the forward slash in the non-working htaccess, and everything worked fine!</p>
<p>Note: this may not work for you, as I have seen articles where REMOVING the forward slash was the solution. It is entirely dependent on your specific apache config and more importantly, your apache version. This is because there have been changes in how apache matches redirects in recent releases.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/07/22/zend-framework-htaccess-url-rewrite-infinite-loop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Framework: module specific layout</title>
		<link>http://blog.vandenbos.org/2009/07/19/zend-framework-module-specific-layout/</link>
		<comments>http://blog.vandenbos.org/2009/07/19/zend-framework-module-specific-layout/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 14:30:00 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[bootstrap]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Zend_Application]]></category>
		<category><![CDATA[zend_layout]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=130</guid>
		<description><![CDATA[In this article I will show you how set up module specific layouts. Many people find it confusing that module resources like layouts are always loaded, regardless of the module requested. The reason for this is that at the time of bootstrap, the request is not yet determined and the application does not know what [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I will show you how set up module specific layouts. Many people find it confusing that module resources like layouts are always loaded, regardless of the module requested. The reason for this is that at the time of bootstrap, the request is not yet determined and the application does not know what module was requested. To set up resources like layouts, databases, translations etc. for specific modules ONLY when that module is requested, your best bet is a front controller plugin or action helper.</p>
<p><span id="more-130"></span></p>
<h2>Usage example</h2>
<p>Default layout settings in application.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>layout<span style="color: #339933;">.</span>layout <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;default&quot;</span>
resources<span style="color: #339933;">.</span>layout<span style="color: #339933;">.</span>layoutPath <span style="color: #339933;">=</span> APPLICATION_PATH <span style="color: #0000ff;">&quot;/views/layouts&quot;</span></pre></div></div>

<p>Then, if you use my ModuleSetup resource as described in <a href="http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/">module config</a>, you can set the module layout options in the module.ini for that module:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>layout<span style="color: #339933;">.</span>layout <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;modulename_default&quot;</span>
&nbsp;
<span style="color: #339933;">;</span> this layoutpath is relative to the directory of the module itself
<span style="color: #339933;">;</span> in this <span style="color: #b1b100;">case</span><span style="color: #339933;">:</span> application<span style="color: #339933;">/</span>modules<span style="color: #339933;">/</span>modulename<span style="color: #339933;">/</span>views<span style="color: #339933;">/</span>layouts
resources<span style="color: #339933;">.</span>layout<span style="color: #339933;">.</span>layoutPath <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;views/layouts&quot;</span></pre></div></div>

<p>or, you can set the module config in your application.ini normally, as described in the Zend Framework reference:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">modulename<span style="color: #339933;">.</span>resources<span style="color: #339933;">.</span>layout<span style="color: #339933;">.</span>layout <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;modulename_default&quot;</span>
&nbsp;
<span style="color: #339933;">;</span> this layoutpath is relative to the directory of the module itself
<span style="color: #339933;">;</span> in this <span style="color: #b1b100;">case</span><span style="color: #339933;">:</span> application<span style="color: #339933;">/</span>modules<span style="color: #339933;">/</span>modulename<span style="color: #339933;">/</span>views<span style="color: #339933;">/</span>layouts
modulename<span style="color: #339933;">.</span>resources<span style="color: #339933;">.</span>layout<span style="color: #339933;">.</span>layoutPath <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;views/layouts&quot;</span></pre></div></div>

<p><em>* note: you can set all options for module layouts sources the same way as for the application layout resource. If you don&#8217;t specify a different layoutPath, the standard path is used</em></p>
<p>The result is that when the module &#8216;modulename&#8217; is requested, the layout &#8216;modulename_default.phtml&#8217; in the directory &#8216;application/modules/modulename/views/layouts&#8217; is used. Otherwise, the main layout is used.</p>
<h2>Code</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Rexus_Controller_Plugin_RequestedModuleLayoutLoader
    <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_plugin_Abstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preDispatch<span style="color: #009900;">&#40;</span>Zend_Controller_Request_Abstract <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$config</span>     <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$moduleName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$moduleName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'resources'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$layoutScript</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$moduleName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'resources'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#93;</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;">-&gt;</span><span style="color: #004000;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$layoutScript</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;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$moduleName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'resources'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layoutPath'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$layoutPath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$moduleName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'resources'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layout'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'layoutPath'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$moduleDir</span> <span style="color: #339933;">=</span> Zend_Controller_Front<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">-&gt;</span><span style="color: #004000;">setLayoutPath</span><span style="color: #009900;">&#40;</span>
                <span style="color: #000088;">$moduleDir</span><span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span> <span style="color: #339933;">.</span><span style="color: #000088;">$layoutPath</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>To use this, drop the class above in your library and set the following in your application.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>frontController<span style="color: #339933;">.</span>plugins<span style="color: #339933;">.</span>layoutloader <span style="color: #339933;">=</span> Rexus_Controller_Plugin_RequestedModuleLayoutLoader</pre></div></div>

<p>If you want to know more about handling other types of resources with modules, check my post about <a href="http://blog.vandenbos.org/2009/07/09/zend-framework-per-module-translation-sources/">module translation sources</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/07/19/zend-framework-module-specific-layout/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Zend Framework: per module translation sources</title>
		<link>http://blog.vandenbos.org/2009/07/09/zend-framework-per-module-translation-sources/</link>
		<comments>http://blog.vandenbos.org/2009/07/09/zend-framework-per-module-translation-sources/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 23:01:20 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[translation]]></category>
		<category><![CDATA[Zend_Translate]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=106</guid>
		<description><![CDATA[Separate modules should be able to have separate Zend_Translate sources. As can be read in my earlier post about , I am making my modules completely autonomous in their config. That also means they should have their own translation sources that are automatically added to the main Zend_Translate instance for easy reference. In this article [...]]]></description>
			<content:encoded><![CDATA[<p>Separate modules should be able to have separate Zend_Translate sources. As can be read in my earlier post about <a href="http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/">module configuration</a>, I am making my modules completely autonomous in their config. That also means they should have their own translation sources that are automatically added to the main Zend_Translate instance for easy reference. In this article I will show you how to set this up.</p>
<p><span id="more-106"></span><br />
The standard zend application resource Zend_Application_Resource_Translate doesn&#8217;t support this. If you use that resource and include translate settings in your module.ini, a separate Zend_Translate instance will be added to the resource container for that module. By default, the resource also sets the registry key &#8216;Zend_Translate&#8217; to the new instance every time the resource is called in the bootstrap process. Because you don&#8217;t know the module load order, you don&#8217;t know what instance the registry will contain.</p>
<p>This has an important drawback: the stock translate view helper, Zend_Form and other Zend_Translate aware ZF components automatically check for a Zend_Translate instance in the registry under the key &#8216;Zend_Translate&#8217;. This will lead to unexpected results.</p>
<p>There are workarounds, but they are not convenient in my opinion. Another example: to get at the translations for your module from your controller, you would have to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$moduleTranslate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulenamehere'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'translate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>to get to the main translate instance:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mainTranslate</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'translate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And the shortest version could not be used, because you wouldn&#8217;t know which instance it contains!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$unknownTranslate</span> <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Translate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>My solution was building a slightly different version of Zend_Application_Resource_Translate. It checks if the registry key is already set first. If not, it creates a new instance of Zend_Translate and assigns it to the registry. If there already is a registry key, the resource fetches the existing instance and calls addTranslation on it. This way, all your translation sources are neatly merged.</p>
<h2>Usage example</h2>
<p>Default translate settings in application.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>translate<span style="color: #339933;">.</span>data <span style="color: #339933;">=</span> APPLICATION_PATH <span style="color: #0000ff;">&quot;/languages&quot;</span>
resources<span style="color: #339933;">.</span>translate<span style="color: #339933;">.</span>adapter <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Array&quot;</span>
resources<span style="color: #339933;">.</span>translate<span style="color: #339933;">.</span>options<span style="color: #339933;">.</span>scan <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;filename&quot;</span></pre></div></div>

<p>Then, if you use my ModuleSetup resource as described in <a href="http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/">module config</a>, you can set the module translation options in the module.ini for that module:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>translate<span style="color: #339933;">.</span>data <span style="color: #339933;">=</span> APPLICATION_PATH <span style="color: #0000ff;">&quot;/modules/modulename/languages&quot;</span></pre></div></div>

<p>or, you can set the module config in your application.ini, as described in the Zend Framework reference:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">modulename<span style="color: #339933;">.</span>resources<span style="color: #339933;">.</span>translate<span style="color: #339933;">.</span>data <span style="color: #339933;">=</span> APPLICATION_PATH <span style="color: #0000ff;">&quot;/modules/modulename/languages&quot;</span></pre></div></div>

<p><em>* note: you can set all options for module translation sources the same way as for the application translate resource, except &#8216;adapter&#8217;. This is because Zend_Translate::addTranslation doesn&#8217;t support it.</em></p>
<p>application/languages/nl.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'application'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'applicatie'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>application/modules/modulename/languages/nl.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'module example'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'module voorbeeld'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After bootstrap, Zend_Registry::get(&#8216;Zend_Translate&#8217;) contains the merged tranlation sources. A var_dump of Zend_Registry::get(&#8216;Zend_Translate&#8217;)-&gt;getMessages() will show:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array</span>
    <span style="color: #0000ff;">'application'</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'applicatie'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
    <span style="color: #0000ff;">'module example'</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'module voorbeeld'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span></pre></div></div>

<h2>Code</h2>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Rexus_Application_Resource_Translate <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Resource_ResourceAbstract
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">const</span> DEFAULT_REGISTRY_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Zend_Translate'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @var Zend_Translate
     */</span>
    protected <span style="color: #000088;">$_translate</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Defined by Zend_Application_Resource_Resource
     *
     * @return Zend_Translate
     */</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: #666666; font-style: italic;">/*
         * The translate settings for the application.ini should be loaded first
         * to set all necessary defaults, most importantly the adapter to use
         *
         * Since we can't know the load order of modules and/or application bootstrap
         * we set the application translate as dependecy if we are not the main Bootstrap
         */</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Bootstrap'</span> <span style="color: #339933;">!==</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</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>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getApplication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'translate'</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><span style="color: #004000;">getTranslate</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: #009933; font-style: italic;">/**
     * Retrieve translate object
     *
     * @return Zend_Translate
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTranslate<span style="color: #009900;">&#40;</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</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;">'No translation source data provided in the ini file for: '</span>
                <span style="color: #339933;">.</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$adapter</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adapter'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'adapter'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> Zend_Translate<span style="color: #339933;">::</span><span style="color: #004000;">AN_ARRAY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$locale</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'locale'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'locale'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$translateOptions</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'options'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'options'</span><span style="color: #009900;">&#93;</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: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'registry_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'registry_key'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
             ? <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'registry_key'</span><span style="color: #009900;">&#93;</span>
             <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">DEFAULT_REGISTRY_KEY</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// If no translate object was set in the registry we create it.</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">isRegistered</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</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>_createTranslation<span style="color: #009900;">&#40;</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;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">,</span> <span style="color: #000088;">$translateOptions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// if there is, we should add a translation source to the existing translate object</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">isRegistered</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</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>_translate <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addTranslation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">,</span> <span style="color: #000088;">$translateOptions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_translate<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_translate<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    protected <span style="color: #000000; font-weight: bold;">function</span> _createTranslation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$adapter</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</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>_translate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Translate<span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$adapter</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">,</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;
    protected <span style="color: #000000; font-weight: bold;">function</span> _addTranslation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</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>_translate<span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTranslation</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">,</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: #009900;">&#125;</span></pre></div></div>

<p>To use this resource instead of the stock one, just drop it into your library. It will automatically be chosen over the stock one, because it has the same name. Of course, this only works correctly if you set the prefix and path for your resources in your application.ini like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">pluginPaths<span style="color: #339933;">.</span>Rexus_Application_Resource <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Rexus/Application/Resource&quot;</span></pre></div></div>

<p>Improvements and comments are always welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/07/09/zend-framework-per-module-translation-sources/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Zend Framework: module config</title>
		<link>http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/</link>
		<comments>http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 22:11:29 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[bootstrap]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[Zend_Application]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=66</guid>
		<description><![CDATA[Zend Framework supports modules, but in my opinion, not in a modular way. I have been trying to set up self-containing modules with their own configuration. The objective is to have an architecture where I can just drop a module in the modules directory, and it will work immediately without further configuration.
Now that there is [...]]]></description>
			<content:encoded><![CDATA[<p>Zend Framework supports modules, but in my opinion, not in a modular way. I have been trying to set up self-containing modules with their own configuration. The objective is to have an architecture where I can just drop a module in the modules directory, and it will work immediately without further configuration.</p>
<p>Now that there is Zend Application with the Modules Resource, that is almost possible. There is one problem. The module specific config still has to be put in application.ini. On the Zend Framework mailinglists, many people are clamoring for module specific configuration files. In this article I will explain how to set up modules with their own config files.</p>
<p><span id="more-66"></span><br />
Of course as a good developer should, I first started searching for a solution by someone else. I found lots of complaints, but no solutions, until I happened upon Jeroen Keppens&#8217; <a href="http://blog.keppens.biz/" target="_blank">blog</a>. He has been busy creating a solution to this problem as can be read in this <a href="http://blog.keppens.biz/2009/06/zend-framework-module-specific-config.html" target="_blank">post</a>.</p>
<p>In a nutshell, his solution is this: he has extended Zend_Application_Module_Bootstrap to automatically register and execute a bootstrap resource called Moduleconfig, that searches for ini files in the configs directory of the module. These ini settings are then used as the options for the module bootstrap. This way, a module can set up its own resources.</p>
<p>This is a valid approach and it works, but I had a few problems with it.</p>
<ul>
<li>I found it impossible to load a frontcontroller plugin in the module config. The frontcontroller resource would get called by the module bootstrap, but the frontcontroller bootstrap resource looks at the application options for plugins and ignores module options so it would do nothing.</li>
<li>A nitpick: the settings from the module ini files don&#8217;t become part of the main application options. This makes them harder to get at in your controllers. Instead of

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p> you need to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulenamehere'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ul>
<p>I have come up with a solution that is strongly based on Jeroen&#8217;s solution, but with an important difference. Instead of letting each module bootstrap get its own config when it is bootstrapped, I chose to create a resource for the main bootstrap that looks for config files in all module config directories and merges them with the application options. This way, the application options array looks the same as if you would have put the ini settings directly in the application.ini.</p>
<p>First, I will show you how to use this solution. Then I&#8217;ll share my code with you so you can use it for yourself.</p>
<h2>Usage</h2>
<p>In your application.ini, you set the resources to be loaded. Note that the resources are loaded in the order you provide them. The Bootstrap resource that is going to do the module setup for us is called Modulesetup. It needs to be loaded as the very first resource, so put it at the top of you [production] segment:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>modulesetup<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span></pre></div></div>

<p>Directly after that I set the modules resource, so that all module-specific resources are loaded first:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>modules<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span></pre></div></div>

<p>Then we create a module.ini in /path/to/application/modules/modulename/configs/module.ini. In that file you can set anything you want, just as if you set it in application.ini. There is one difference: in application.ini you would set it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">modulename<span style="color: #339933;">.</span>resources<span style="color: #339933;">.</span>frontcontroller<span style="color: #339933;">.</span>plugins<span style="color: #339933;">.</span>foo <span style="color: #339933;">=</span> bar</pre></div></div>

<p>In your module.ini, you don&#8217;t have to set the module prefix, this is done for you:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">resources<span style="color: #339933;">.</span>frontcontroller<span style="color: #339933;">.</span>plugins<span style="color: #339933;">.</span>foo <span style="color: #339933;">=</span> bar</pre></div></div>

<p>You can now get at your module specific settings in the following ways:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulenamehere'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>the same but longer:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules'</span><span style="color: #009900;">&#41;</span>
       <span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulenamehere'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And to get your module specific loaded resources:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvokeArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bootstrap'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetGet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulenamehere'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'resourcenamehere'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Code</h2>
<p>All you need is the following class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Rexus_Application_Resource_Modulesetup
    <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Resource_ResourceAbstract
<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>_getModuleSetup<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: #009933; font-style: italic;">/**
     * Load the module's ini files
     *
     * @return void
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> _getModuleSetup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$bootstrap</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bootstrap</span> instanceof Zend_Application_Bootstrap_Bootstrap<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_Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid bootstrap class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$bootstrap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frontcontroller'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$front</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bootstrap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frontcontroller'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$modules</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getControllerDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modules</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$module</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$configPath</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$front</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#41;</span> 
                         <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'configs'</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$configPath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$cfgdir</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DirectoryIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$configPath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$appOptions</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cfgdir</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</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;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isFile</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;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFilename</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_loadOptions<span style="color: #009900;">&#40;</span><span style="color: #000088;">$configPath</span> 
                                 <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$filename</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;">&#40;</span><span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$cfgtype</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$len</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;">$cfgtype</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$filename</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;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cfgtype</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'module'</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: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #339933;">,</span> <span style="color: #000088;">$appOptions</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: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$appOptions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                    <span style="color: #000088;">$appOptions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>
                                        <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$appOptions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</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;">else</span> <span style="color: #009900;">&#123;</span>
                                    <span style="color: #000088;">$appOptions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">;</span>
                                <span style="color: #009900;">&#125;</span>
                            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #000088;">$appOptions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000088;">$appOptions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'resources'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$cfgtype</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOptions</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$appOptions</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: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Load the config file
     *
     * @param string $fullpath
     * @return array
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> _loadOptions<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fullpath</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: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fullpath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fullpath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'ini'</span><span style="color: #339933;">:</span>
                    <span style="color: #000088;">$cfg</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fullpath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                                                    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEnvironment</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'xml'</span><span style="color: #339933;">:</span>
                    <span style="color: #000088;">$cfg</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Xml<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fullpath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                                                    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEnvironment</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                    throw <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid format for config file'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</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;">'File does not exist'</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;">$cfg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toArray</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>Put it in your library directory and don&#8217;t forget to set the prefix for your own resources in your application.ini like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">pluginPaths<span style="color: #339933;">.</span>Rexus_Application_Resource <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Rexus/Application/Resource&quot;</span></pre></div></div>

<p>I use Rexus as the prefix for all my own stuff, but you can change this of course.</p>
<p>I am curious what you think.</p>
<p><em>edit: comment from Michel: changed the way the module directory is determined from hardcoded to dynamic</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/07/07/zend-framework-module-config/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>First Post</title>
		<link>http://blog.vandenbos.org/2009/04/06/hello-world/</link>
		<comments>http://blog.vandenbos.org/2009/04/06/hello-world/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 18:59:41 +0000</pubDate>
		<dc:creator>Matthijs</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[grid]]></category>

		<guid isPermaLink="false">http://blog.vandenbos.org/?p=1</guid>
		<description><![CDATA[Welcome to my website. On this site I will be posting about all things that have to do with web development with some emphasis on Zend Framework. My aim is to provide a place where developers will find many useful tips and snippets to use in their own projects. To do that, I will not [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to my website. On this site I will be posting about all things that have to do with web development with some emphasis on Zend Framework. My aim is to provide a place where developers will find many useful tips and snippets to use in their own projects. To do that, I will not only publish about my own insights and code, but also about great pieces of code by other developers.</p>
<p>Let&#8217;s get started right away: I have started finetuning a generic grid component for Zend Framework that I have been using for my own projects for a while now. In my experience it severely cuts development time of web applications; because as we all know, web applications are at their core nothing more than lists and CRUD. There is a limitation that many people will regret: it can&#8217;t do everything. I will post the first draft with documentation soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vandenbos.org/2009/04/06/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
