<?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>Web Development and stuff...</title>
	<atom:link href="http://lenss.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://lenss.nl</link>
	<description>Thijs Lensselink - Web Developer</description>
	<lastBuildDate>Sun, 15 Aug 2010 12:14:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Community Spirit T-Shirt Design Competition</title>
		<link>http://lenss.nl/2010/08/php-community-spirit-t-shirt-design-competition/</link>
		<comments>http://lenss.nl/2010/08/php-community-spirit-t-shirt-design-competition/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 12:02:22 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Contest]]></category>
		<category><![CDATA[Spirit]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=775</guid>
		<description><![CDATA[I entered a design for the PHP Community Spirit T-Shirt Design Competition. And it got approved today. It&#8217;s a simple design that uses the PHP logo colors and font. If you like it you can vote for it by following the design below.]]></description>
			<content:encoded><![CDATA[<p>I entered a design for the PHP Community <a href="http://php-spirit.strutta.com/" target="_blank">Spirit T-Shirt Design Competition</a>. And it got approved today. It&#8217;s a simple design that uses the PHP logo colors and font. If you like it you can vote for it by following the design below.</p>
<p><a href="http://php-spirit.strutta.com/entries/72596" title="View full size"><img src="http://www.strutta.com/image-cacher/f:640:360/aHR0cDovL3VwbG9hZHMuZmlsZXMuc3RydXR0YS5jb20vZW50cnkvMTU0NTk5Ni8xMjgxNzczMjQx" align="center" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/08/php-community-spirit-t-shirt-design-competition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New elePHPant :)</title>
		<link>http://lenss.nl/2010/08/new-elephpant/</link>
		<comments>http://lenss.nl/2010/08/new-elephpant/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 09:22:59 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[/home]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[elePHPant]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=767</guid>
		<description><![CDATA[After purchasing a new batch of the friendly blue guys. Damien Seguy was so friendly to send me an early Christmas present I have some small versions left by the way. So if you are one of those people looking. Drop me a line or leave a comment.]]></description>
			<content:encoded><![CDATA[<p>After purchasing a new batch of the friendly blue guys. <a href="http://www.nexen.net/">Damien Seguy</a> was so friendly to send me an early Christmas present <img src='http://lenss.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://lenss.nl/wp-content/uploads/2010/08/elephpant.jpg" rel="lightbox[767]"><img class="aligncenter size-medium wp-image-772" title="elephpant" src="http://lenss.nl/wp-content/uploads/2010/08/elephpant-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>I have some small versions left by the way. So if you are one of those people looking. Drop me a line or leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/08/new-elephpant/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Returning Blocks from controllers without layout attached in Magento</title>
		<link>http://lenss.nl/2010/07/returning-blocks-from-controllers-without-layout-attached-in-magento/</link>
		<comments>http://lenss.nl/2010/07/returning-blocks-from-controllers-without-layout-attached-in-magento/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 08:31:53 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[layout]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=763</guid>
		<description><![CDATA[When working in the admin environment of Magento i had to add a controller action that was called by an Ajax request. The problem however is that all layout data is returned as well when calling $this->renderLayout(); from the controller. So my next attempt was to try to render the block separately and adding it [...]]]></description>
			<content:encoded><![CDATA[<p>When working in the admin environment of Magento i had to add a controller action that was called by an Ajax request. The problem however is that all layout data is returned as well when calling </p>
<pre name="code" class="php">
$this->renderLayout();
</pre>
<p>from the controller. So my next attempt was to try to render the block separately and adding it to the layout. </p>
<pre name="code" class="php">
$this->_initCustomer();
$this->getResponse()->setBody(
            $this->getLayout()->createBlock('block/location')
            ->setCustomerId(Mage::registry('current_customer')->getId())
            ->setData('list', $list)
            ->setUseAjax(true)
            ->toHtml()
);
</pre>
<p>This kinda worked. But now i had no more control over the template used. Or maybe i missed that part. But i don&#8217;t like to specify my Block anyway Magento should pick this up automatically.</p>
<p>Solving this issue is actually quite easy. The only thing we need to do is change the layout structure of the module. We change the name to root. And that&#8217;s it!</p>
<pre name="code" class="xml">
<block type="block/location" name="root" template="template/location"/>
</pre>
<p>The name attribute tells Magento it is a root block so no need for the rest of the layout. </p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/07/returning-blocks-from-controllers-without-layout-attached-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error&#8217;d</title>
		<link>http://lenss.nl/2010/06/errord/</link>
		<comments>http://lenss.nl/2010/06/errord/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 18:33:48 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[error]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=758</guid>
		<description><![CDATA[I really like the eclipse platform. But yesterday morning it was my own WTF moment when my IDE crashed while building a large project.]]></description>
			<content:encoded><![CDATA[<p>I really like the eclipse platform. But yesterday morning it was my own WTF moment when my IDE crashed while building a large project.</p>
<p><a href="http://lenss.nl/wp-content/uploads/2010/06/eclipse_error.jpg" rel="lightbox[758]"><img src="http://lenss.nl/wp-content/uploads/2010/06/eclipse_error-300x125.jpg" alt="" title="eclipse_error" width="300" height="125" class="alignleft size-medium wp-image-757" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/06/errord/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Override controllers in Magento</title>
		<link>http://lenss.nl/2010/06/override-controllers-in-magento/</link>
		<comments>http://lenss.nl/2010/06/override-controllers-in-magento/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 09:43:45 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=753</guid>
		<description><![CDATA[The last time i had to rewrite one of the core Magento blocks. And that turned out to be quite easy. My new challenge was to rewrite / overwrite one of the Core admin controllers. In this case the Mage_Adminhtml_CustomerController. I had no idea where to start so i did some googling beforehand. And came [...]]]></description>
			<content:encoded><![CDATA[<p>The last time i had to rewrite one of the core Magento blocks. And that turned out to be quite easy. My new challenge was to rewrite / overwrite one of the Core admin controllers. In this case the Mage_Adminhtml_CustomerController. </p>
<p>I had no idea where to start so i did some googling beforehand. And came to the conclusion that a lot of people are trying to do this. Because of this there is a long list of solutions to solve this. And in most cases developers just advice to drop the Core class in the local folder and work from there. But that doesn&#8217;t really make sense. First of all it code duplication in the worst form. And besides that all cool <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">OO</a> stuff like extending is gone.</p>
<p>And since Magento is such a flexible system. There must be a good clean way to solve this. One <a href="http://www.magentocommerce.com/boards/viewthread/16224/">thread</a> i found had some good info. And i used it as my starting point. There was one problem with this thread. The XML used seems to be an old form of rewriting in Magento.<br />
I found a (lost it) post by one of the Magento devs that shows a new and more clean way of defining this in XML.</p>
<p>In the last post i already created the [Namespace]_All.xml module config. And we can use it for this as well. So we start by telling Magento we are using our own [Namespace_]_Adminhtml module.</p>
<pre name="code" class="xml">
<[namespace]_Adminhtml>
    <active>true</active>
    <codePool>local</codePool>
    <depends>
        <Mage_Adminhtml />
    </depends>
</[namespace]_Adminhtml>
</pre>
<blockquote><p>create local/Namespace/Adminhtml/controllers/CustomerController.php</p></blockquote>
<p>The next thing to do is create the actual controller. And add an include line on top to the original file. Magento does not use autoloading for the controllers in this way.</p>
<pre name="code" class="php">
include_once("Mage/Adminhtml/controllers/CustomerController.php");

class [namespace]_Adminhtml_CustomerController extends Mage_Adminhtml_CustomerController
{
	public function somenewAction()
	{

	}
}
</pre>
<p>Now the Core CustomerController is replaced by our own namespaced version. But it still retains all functionality of the parent.</p>
<p>The only thing left is to create the config file for this module. And tell it to rewrite to the new [namespace]</p>
<blockquote><p>Create local/[namespace]/Adminhtml/etc/config.xml</p></blockquote>
<pre name="code" class="xml">
<config>
	<modules>
        <[namespace]_Adminhtml>
            <version>0.1.0</version>
        <[namespace]_Adminhtml>
    </modules>

	<admin>
    	<routers>
    		<adminhtml>
    			<args>
    				<modules>
    					<[namespace]_Adminhtml before="Mage_Adminhtml">[namespace]_Adminhtml</[namespace]_Adminhtml>
    				</modules>
    			</args>
    		</adminhtml>
    	</routers>
    </admin>
</config>
</pre>
<p>The config section is placed inside the admin tags. because the controller in question is an admin controller. We basically tell Magento that we will be using our own Adminhtml module instead of the Core one. But it will of course fall back on the Core functionality when methods have not been overwritten.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/06/override-controllers-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewriting blocks in Magento</title>
		<link>http://lenss.nl/2010/06/rewriting-blocks-in-magento/</link>
		<comments>http://lenss.nl/2010/06/rewriting-blocks-in-magento/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 14:20:42 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[rewrite]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=743</guid>
		<description><![CDATA[The last few days i have been toying with Magento. and mainly trying to wrap my head around the file structure. It takes quite some time to find all files. So i will be making notes here to keep track of my own progress Today i wanted to add a tab in the customer section [...]]]></description>
			<content:encoded><![CDATA[<p>The last few days i have been toying with <a href="http://www.magentocommerce.com/">Magento</a>. and mainly trying to wrap my head around the file structure. It takes quite some time to find all files. So i will be making notes here to keep track of my own progress <img src='http://lenss.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Today i wanted to add a tab in the customer section of the admin. I am working on a new module and this should be configurable on a per user basis. There for i needed an extra tab to the customer &gt; Manage customers &gt; [customer x] page.</p>
<p>The first challenge was to figure out where Magento stores the tab menu data. I was hoping this came from a database. But after some searching i couldn&#8217;t find any reference. It seems to be hard coded in tab files. The customer tab in question can be found here:</p>
<blockquote><p>app/code/core/Mage/Adminhtml/Block/Customer/Edit/tabs.php</p></blockquote>
<p>We could of course edit this class. But that&#8217;s not according the Magento way. We need to create a local copy of this class. preferably under my own namespace.</p>
<p>To make this happen we first need to tell Magento we are rewriting core modules. So we start of by creating the following file</p>
<blockquote><p>app/etc/modules/[namespace]_All.xml</p></blockquote>
<p>And we add the following lines</p>
<pre name="code" class="xml">
<?xml version="1.0"?>
<config>
    <modules>
        <Strawberries_Core>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Core />
            </depends>
        </Strawberries_Core>
    </modules>
</config>
</pre>
<p>This will tell Magento we have a Core folder under our own namespace. But it still depends on the Mage_Core classes if they are not available in the namespaced location.</p>
<p>Next we need to setup the [namespace]_Core module. We create the folder structure under our own namspace</p>
<blockquote><p>app/code/local/[namespace]/Core/etc</p></blockquote>
<p>And we create a new config file here (config.xml) where we will do the actual class rewriting.</p>
<pre name="code" class="xml">
<?xml version="1.0"?>
<config>
    <modules>
        <[namespace]_Core>
            <version>0.1.0</version>
        </[namespace]_Core>
    </modules>
    <global>
        <blocks>
        	<adminhtml>
        		<rewrite>
        			<customer_edit_tabs>[namespace]_Adminhtml_Block_Customer_Edit_Tabs</customer_edit_tabs>
        		</rewrite>
        	</adminhtml>
        </blocks>
    </global>
</config>
</pre>
<p>We use the <blocks> tag to tell Magento we are rewriting a Block class. And then we setup the actual rewrite. </p>
<blockquote><p>Mage_Adminhtml_Block_Customer_Edit_Tabs is now rewritten too [namespace]_Adminhtml_Block_Customer_Edit_Tabs</p></blockquote>
<p>The only thing left now is to create the Block class which is located in </p>
<blockquote><p>app/code/local/[namespace]/Adminhtml/Block/Customer/Edit/Tabs.php</p></blockquote>
<pre name="code" class="php">
class [namespace]_Adminhtml_Block_Customer_Edit_Tabs extends Mage_Adminhtml_Block_Customer_Edit_Tabs
{
    protected function _beforeToHtml()
    {
	$this->addTab('modulename', array(
            'label'     => Mage::helper('customer')->__('Modulename'),
            'class'     => 'ajax',
            'url'       => $this->getUrl('*/*/modulename', array('_current' => true)),
        ));

        $this->_updateActiveTab();
        return parent::_beforeToHtml();
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/06/rewriting-blocks-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nerdiness</title>
		<link>http://lenss.nl/2010/05/nerdiness/</link>
		<comments>http://lenss.nl/2010/05/nerdiness/#comments</comments>
		<pubDate>Fri, 21 May 2010 07:01:18 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[/home]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Nerd]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=731</guid>
		<description><![CDATA[Ok so i had nothing todo for a few minutes and found a link to this page. I am never really into this stuff. But it looked funny and i had nothing to do. So i walked through the questions&#8230; and the result Supreme Nerd. Apply for a professorship at MIT now!!!. Another nerdy thing [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so i had nothing todo for a few minutes and found a <a href="http://www.nerdtests.com/ft_nq.php">link</a> to this page. I am never really into this stuff. But it looked funny and i had nothing to do. So i walked through the questions&#8230; and the result <img src='http://lenss.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Supreme Nerd. Apply for a professorship at MIT now!!!.</strong></p>
<p><a href="http://www.nerdtests.com/ft_nq.php"><br />
<img src="http://www.nerdtests.com/images/ft/nq/bfcfa5649e.gif" alt="I am nerdier than 91% of all people. Are you a nerd? Click here to take the Nerd Test, get nerdy images and jokes, and write on the nerd forum!"></a></p>
<p>Another nerdy thing i picked up was that Ilia Alshanetsky&#8217;s <a href="http://ilia.ws/archives/217-Scalar-Type-Hints-are-Here!.html">scalar type hints</a> patch has been merged with the PHP trunk. Great stuff. Have been waiting for this for a while.</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/05/nerdiness/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A new look for lenss.nl</title>
		<link>http://lenss.nl/2010/04/a-new-look-for-lenss-nl/</link>
		<comments>http://lenss.nl/2010/04/a-new-look-for-lenss-nl/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 19:17:30 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[/home]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=729</guid>
		<description><![CDATA[This long Easter weekend gave me some time to create a new theme for this blog. So after a day of work this is the result. I was a bit tired of the dark unreadable format. At the moment i am still tweaking here and there but it looks fine!]]></description>
			<content:encoded><![CDATA[<p>This long Easter weekend gave me some time to create a new theme for this blog. So after a day of work this is the result. I was a bit tired of the dark unreadable format. At the moment i am still tweaking here and there but it looks fine!</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/04/a-new-look-for-lenss-nl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Month of PHP Security 2010</title>
		<link>http://lenss.nl/2010/03/month-of-php-security-2010/</link>
		<comments>http://lenss.nl/2010/03/month-of-php-security-2010/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 11:42:38 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[php-security]]></category>
		<category><![CDATA[SektionEins]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=717</guid>
		<description><![CDATA[After a successful experiment a while back Month of the PHP Bugs. Stefan Esser and SektionEins is at it again. This time with Month of PHP Security. A gathering for PHP and security gurus a like. The call for papers is open for submission. There are some nice prices to walk away with. So what [...]]]></description>
			<content:encoded><![CDATA[<p>After a successful experiment a while back <a href="http://blog.php-security.org/archives/71-Month-of-PHP-Bugs-and-PHP-5.2.1.html">Month of the PHP Bugs</a>. Stefan Esser and <a href="http://www.sektioneins.com/">SektionEins</a> is at it again. This time with Month of PHP Security. A gathering for PHP and security gurus a like. The call for papers is <a href="http://www.php-security.org/">open for submission</a>. </p>
<p>There are some nice prices to walk away with. So what you waiting for?</p>
<ul>
<li>New vulnerability in PHP [1] (not simple safe_mode, open_basedir bypass vulnerabilities)</li>
<li>New vulnerability in PHP related software [1] (popular 3rd party PHP extensions/patches)</li>
<li>Explain a single topic of PHP application security in detail (such as guidelines on how to store passwords)</li>
<li>Explain a complicated vulnerability in/attack against a PHP widespread application [1]</li>
<li>Explain a complicated topic of attacking PHP (e.g. explain how to exploit heap overflows in PHP&#8217;s heap implementation)</li>
<li>Explain how to attack encrypted PHP applications</li>
<li>Release of a new open source PHP security tool</li>
<li>Other topics related to PHP or PHP application security</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/03/month-of-php-security-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework Bootstrapping Modules</title>
		<link>http://lenss.nl/2010/02/zend-framework-bootstrapping-modules/</link>
		<comments>http://lenss.nl/2010/02/zend-framework-bootstrapping-modules/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 20:04:38 +0000</pubDate>
		<dc:creator>Thijs Lensselink</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://lenss.nl/?p=692</guid>
		<description><![CDATA[I am working on a small API for bluesignal and i wanted a modular architecture. I have done this before using the Zend Framework. But this time i wanted a bit more control while loading the modules. And adding a Bootstrap class would seem like a good option. The only example i could find involved [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a small API for <a href="http://bluesignal.nl">bluesignal</a> and i wanted a modular architecture. I have done this before using the Zend Framework. But this time i wanted a bit more control while loading the modules. And adding a <a href="http://0x.vc/k">Bootstrap</a> class would seem like a good option. The only example i could find involved loading all bootstraps on every request. Which doesn&#8217;t seem like a good idea. So after reading through the Manual and some blog posts. I decided to give it s shot my self.</p>
<p>The structure i want looks like this.</p>
<p><a href="http://lenss.nl/wp-content/uploads/2010/02/module-based.jpg" rel="lightbox[692]"><img src="http://lenss.nl/wp-content/uploads/2010/02/module-based.jpg" alt="" title="module-based" width="318" height="327" class="aligncenter size-full wp-image-701" /></a></p>
<p>The application.ini file has the following contents:</p>
<blockquote><p>includePaths.library = APPLICATION_PATH &#8220;/../library&#8221;<br />
bootstrap.path = APPLICATION_PATH &#8220;/Bootstrap.php&#8221;<br />
bootstrap.class = &#8220;Bootstrap&#8221;<br />
resources.frontController.moduleDirectory = APPLICATION_PATH &#8220;/modules&#8221;<br />
resources.modules[] = &#8220;default&#8221;<br />
resources.modules[] = &#8220;admin&#8221;</p></blockquote>
<p><strong>includePaths</strong><br />
This sets the applications local library location. Any shared code for this application goes here.</p>
<p><strong>bootstrap.path &#038; class</strong><br />
Define the location and type of the Bootstrap class.</p>
<p><strong>resources</strong><br />
Define the modules location and create a list of modules.</p>
<p>The main Bootstrap class</p>
<p><strong>application/Bootstrap.php</strong></p>
<pre name="code" class="php">
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
</pre>
<p>Load the config parameters for this application and set some debugging settings if needed.</p>
<pre name="code" class="php">
    protected function _initConfiguration()
    {
    	$app = $this->getApplication();
    	$config = $app->getOptions();

    	if (APPLICATION_ENV == 'development') {
	    	    error_reporting(E_ALL &#038; E_STRICT);
	    	    if (isset($config['phpsettings'])) {
		    	        foreach ($config['phpsettings'] as $setting => $value) {
		    		        ini_set($setting, $value);
		    	        }
	    	    }
    	}
    }
</pre>
<p>We need autoloading here because we are using a class from the application library. Right now this causes a problem. A notice is thrown </p>
<blockquote><p>Warning: include_once(FrontController.php) [function.include-once]: failed to open stream: No such file or directory in Zend/Loader.php  on line 147</p></blockquote>
<p>The application responds fine. And this problem seems to be a recurring issue (<a href="http://0x.vc/l">ZF-7224</a>, <a href="http://0x.vc/m">ZF-7550</a>) for the framework. Until now i have not find a graceful fix for this. besides a small <a href="http://0x.vc/n">patch</a> reversion.</p>
<pre name="code" class="php">
    protected function _initAutoload()
    {
		    $autoloader = Zend_Loader_Autoloader::getInstance();
		    $autoloader->setFallbackAutoloader(true);

		    return $autoloader;
    }
</pre>
<p>Setup the controller to register the <strong>Bluess_Modules_Loader</strong> plug-in. And set the <strong>prefixDefaultModule</strong> parameter so we can prefix the default module controllers as well. Just for the sake of consistency. The <strong>Bluess_</strong> namespace is part of my API. And can be changed at will.</p>
<pre name="code" class="php">
   protected function _initController()
    {
    	$this->bootstrap('FrontController');
    	$controller = $this->getResource('FrontController');
       $modules = $controller->getControllerDirectory();
       $controller->setParam('prefixDefaultModule', true);

        $controller->registerPlugin(
               new Bluess_Modules_Loader($modules)
        );

        return $controller;
    }
</pre>
<p>Now the last method. which is a bit weird. And i am probably missing a key factor here. But if this method <strong>resource</strong> is not declared only the default module functions. When declared empty all modules function as they should. This would indicate that this method could be used to load the modules. But i haven&#8217;t found a way to achieve this yet. Except for loading all modules in a row. Which makes no sense for this purpose. So we leave it empty.</p>
<pre name="code" class="php">
protected function _initModules()
    {
		// Call to prevent ZF from loading all modules
    }
</pre>
<p>The most important part here is the controller plug-in. This will be the place where module bootstraps are called from.</p>
<p><strong>application/../library/Bluess/Modules/Loader.php</strong></p>
<pre name="code" class="php">
class Bluess_Modules_Loader extends Zend_Controller_Plugin_Abstract
{
	protected $_modules;
</pre>
<p>Setup the plug-in by passing the applications module list.</p>
<pre name="code" class="php">
	public function __construct(array $modulesList)
	{
		$this->_modules = $modulesList;
	}
</pre>
<p>The <strong>dispatchLoopStartup</strong> method will be called on every request and will do the magic. Based on the current module name we create a new <strong>Zend_Application</strong> with the current modules config file <strong>module.ini</strong>. And we bootstrap it.</p>
<pre name="code" class="php">
	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
	{
		$module = $request->getModuleName();

		if (!isset($this->_modules[$module])) {
			throw new Exception("Module does not exist!");
		}

		$bootstrapPath = $this->_modules[$module];

		$bootstrapFile = dirname($bootstrapPath) . '/Bootstrap.php';
        $class         = ucfirst($module) . '_Bootstrap';
        $application   = new Zend_Application(
        	APPLICATION_ENV,
    		APPLICATION_PATH . '/modules/' . $module . '/configs/module.ini'
		);  

        if (Zend_Loader::loadFile('Bootstrap.php', dirname($bootstrapPath))
        	&#038;&#038; class_exists($class)) {
            $bootstrap = new $class($application);
            $bootstrap->bootstrap();
        }
	}
}
</pre>
<p>Now setup the default module. Once this is done it&#8217;s a nice example for further modules. Make sure the module has it&#8217;s own layout set. </p>
<p><strong>application/modules/default/configs/module.ini</strong></p>
<blockquote><p>default.resources.layout.layout = &#8220;default&#8221;<br />
default.resources.layout.layoutPath = APPLICATION_PATH &#8220;/modules/default/layout&#8221;</p></blockquote>
<p>Setup the modules bootstrap and use it to set the modules model location.</p>
<p><strong>application/modules/default/Bootstrap.php</strong></p>
<pre name="code" class="php">
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
	protected $_moduleName = 'default';

	protected function _initConfiguration()
    {
		$options = $this->getApplication()->getOptions();

    	set_include_path(implode(PATH_SEPARATOR, array(
		    realpath(APPLICATION_PATH . '/modules/' . $this->_moduleName . '/models'),
		    get_include_path(),
		)));

		return $options;
    }
}
</pre>
<p>That&#8217;s all. Now make sure your layout is set correctly and the controllers are prefixed</p>
<p><strong>application/modules/default/layout/default.phtml</strong></p>
<pre name="code" class="php">
echo $this->layout()->content;
</pre>
<p><strong>application/modules/default/controllers/IndexController.php</strong></p>
<pre name="code" class="php">
class Default_IndexController extends Zend_Controller_Action
{
</pre>
<p>It took me a while to get this working like i had it in my mind. But it&#8217;s going the right way. If your interested in a working copy. You can download one <a href="http://0x.vc/j">here</a>.</p>
<p><strong>UPDATE</strong></p>
<p>Matthew has a nice <a href="http://weierophinney.net/matthew/archives/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html#extended">post </a>about some do&#8217;s and don&#8217;ts concerning module based applications</p>
]]></content:encoded>
			<wfw:commentRss>http://lenss.nl/2010/02/zend-framework-bootstrapping-modules/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
