<?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>Philipp Feigl</title>
	<atom:link href="http://www.philippfeigl.de/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philippfeigl.de/blog</link>
	<description>Webdevelopment &#38; Hosting</description>
	<lastBuildDate>Tue, 04 May 2010 11:21:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Module based layouts with Zend Framework</title>
		<link>http://www.philippfeigl.de/blog/2010/05/module-based-layouts-with-zend-framework/</link>
		<comments>http://www.philippfeigl.de/blog/2010/05/module-based-layouts-with-zend-framework/#comments</comments>
		<pubDate>Tue, 04 May 2010 01:30:04 +0000</pubDate>
		<dc:creator>Philipp Feigl</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.philippfeigl.de/blog/?p=4</guid>
		<description><![CDATA[Current version of Zend Framework]]></description>
			<content:encoded><![CDATA[<p>Current version of Zend Framework is completly based on a bootstrapping design pattern.</p>
<p><a title="Zend Framework Resource Plugins" href="http://framework.zend.com/manual/en/zend.application.available-resources.html" target="_blank">Many  resource plugins</a> are available, which can be managed via a config file. One of these is <a title="Zend Framework Resource Plugins" href="http://framework.zend.com/manual/en/zend.application.available-resources.html" target="_blank"></a>Zend_Application_Resource_Layout, which instantiates the layout for you based on the<br />
<em>resources.layout.layoutPath </em>directive in your config.</p>
<p>While this worked fine for me with the initial setup, I wondered how I would have a differnt layout set for another module. Doing that login the in Layout Resource Plugin is no option, because bootstrapping happens before the application knows, which module will be executed.</p>
<p>So the correct way for me to solve the problem was to create a Controller Plugin which changes the layoutPath in the preDispatch method. I wanted to have this working with as little efford as possible, so I tried to stick to an implementation, which assumes the module based layout to reside in a very similar folder structure than what the default module is based on. In my case this would be a typical example:</p>
<p>/application/layouts/scripts/layout.phtml</p>
<p>vs</p>
<p>/application/<strong>admin/</strong>layouts/scripts/layout.phtml</p>
<p>So all I needed to accomplish was</p>
<ul>
<li>Replace application path with module path (which is set via <em>resources.frontController.moduleDirectory</em>)</li>
<li>Check whether specific layout for module exists</li>
<li>Change layoutPath for the according module</li>
</ul>
<p>So after we went over the theory, this is the final controller plugin I&#8217;ve come up, which generically lets me add a <em>/layouts/scripts/</em> folder to each of my modules and loads that. If no layout is found for that module, everything simply runs under the default layout.</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: #000000; font-weight: bold;">class</span> Tarsonis_Controller_Plugin_ModuleLayout <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Plugin_Abstract
<span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * Predispatch function for changing layout by requested module
	 *
	 * @param Zend_Controller_Request_Abstract $request
	 */</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;">$module</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>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$layout</span> <span style="color: #339933;">=</span> Zend_Layout<span style="color: #339933;">::</span><span style="color: #004000;">getMvcInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMvcEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$moduleDirectory</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: #000088;">$module</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$moduleLayoutPath</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH<span style="color: #339933;">,</span> <span style="color: #000088;">$moduleDirectory</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayoutPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$moduleLayoutPath</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$moduleLayoutPath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$layout</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLayoutPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$moduleLayoutPath</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>

]]></content:encoded>
			<wfw:commentRss>http://www.philippfeigl.de/blog/2010/05/module-based-layouts-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wilkommen auf meiner Webseite</title>
		<link>http://www.philippfeigl.de/blog/2008/05/hello-world/</link>
		<comments>http://www.philippfeigl.de/blog/2008/05/hello-world/#comments</comments>
		<pubDate>Fri, 16 May 2008 13:26:37 +0000</pubDate>
		<dc:creator>Philipp Feigl</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://philippfeigl.de/blog/?p=1</guid>
		<description><![CDATA[Ich weiß nicht, wie du]]></description>
			<content:encoded><![CDATA[<p>Ich weiß nicht, wie du den Weg hierher gefunden hast. Hallo auf alle Fälle.</p>
<p>Hier findest du Informationen zu allen Themen, die mit meinem Gewerbe zutun haben. Dazu gehören</p>
<ul>
<li>Webseiten an denen ich arbeite</li>
<li>Informationen über mich selbst</li>
<li>Informationen zu meinen Servern</li>
<li>Programmierrelevante Themen</li>
</ul>
<p>Viel Spaß nun beim stöbern auf meinen Seiten.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.philippfeigl.de/blog/2008/05/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

