<?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>BinaryKitten&#039;s Blog</title>
	<atom:link href="http://binarykitten.me.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://binarykitten.me.uk</link>
	<description></description>
	<lastBuildDate>Mon, 08 Mar 2010 23:20:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Per form stylesheet with Zend_Form</title>
		<link>http://binarykitten.me.uk/dev/zend-framework/274-per-form-stylesheet-with-zend_form.html</link>
		<comments>http://binarykitten.me.uk/dev/zend-framework/274-per-form-stylesheet-with-zend_form.html#comments</comments>
		<pubDate>Mon, 01 Mar 2010 21:58:04 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://binarykitten.me.uk/?p=274</guid>
		<description><![CDATA[I needed to have certain form styles attached when a form is in use. I didn&#8217;t want to do this from the controller each and every time as it was really was only to do with the form and I might want to use the form with it&#8217;s own stylesheet in other places.

The Solution
The solution [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to have certain form styles attached when a form is in use. I didn&#8217;t want to do this from the controller each and every time as it was really was only to do with the form and I might want to use the form with it&#8217;s own stylesheet in other places.<br />
<span id="more-274"></span></p>
<h3>The Solution</h3>
<p>The solution is to extend Zend_form and use the extended version as the basis for all the forms in the application. Here is my Form class.<br />
<code>
<pre class="brush: php">
&lt;?php
class BinaryKitten_Form extends Zend_Form
{
    private $_stylesheets = array(
        &#039;main&#039;=&gt;array(&#039;href&#039;=&gt;&#039;/css/form.css&#039;, &#039;media&#039;=&gt;&#039;screen&#039;)
    );

    public function addStylesheet($href,$media=&#039;screen&#039;)
    {
        $this-&gt;_stylesheets[basename($href)] = array(
            &quot;href&quot;=&gt;$href,
            &quot;media&quot;=&gt;$media
        );
    }

    public function removeStylesheet($href)
    {
        unset($this-&gt;_stylesheets[basename($href)]);
    }

    public function clearStylesheets()
    {
        $this-&gt;_stylesheets = array();
    }

    public function render(Zend_View_Interface $view = null)
    {
        if (null !== $view) {
            $this-&gt;setView($view);
        }
        else {
            $view = $this-&gt;getView();
        }

        foreach ($this-&gt;_stylesheets as $stylesheet) {
            $view-&gt;headLink()-&gt;appendStylesheet($stylesheet[&#039;href&#039;], $stylesheet[&#039;media&#039;]);
        }

        $content = &#039;&#039;;
        foreach ($this-&gt;getDecorators() as $decorator) {
            $decorator-&gt;setElement($this);
            $content = $decorator-&gt;render($content);
        }
        return $content;
    }
}
</pre>
<p></code></p>
<p>Of course you would extend it as usual to create a new form&#8230;.</p>
<pre class="brush: php">
&lt;?php
class BinaryKitten_Form_LoginForm extends BinaryKitten_Form
{
    public function __construct($option = null)
    {
        parent::__construct($option);
        $decorators = array(
            array(&#039;ViewHelper&#039;),
            array(&#039;Label&#039;, array(
                &#039;requiredSuffix&#039;=&gt;&quot; *&quot;
            )),
            array(&#039;HtmlTag&#039;, array(&#039;tag&#039;=&gt;&#039;div&#039;))
        );

        $username = new Zend_Form_Element_Text(&#039;username&#039;);
        $username
            -&gt;setLabel(&#039;Username&#039;)
            -&gt;setRequired(true)
            -&gt;addValidator(&#039;NotEmpty&#039;, true)
            -&gt;addFilter(&quot;StringTrim&quot;)
            -&gt;addErrorMessage(&#039;Please Enter your Username&#039;)
            -&gt;setDecorators($decorators);

        $password = new Zend_Form_Element_Password(&#039;password&#039;);
        $password
            -&gt;setLabel(&#039;Password&#039;)
            -&gt;setRequired(true)
            -&gt;addValidator(&#039;NotEmpty&#039;, true)
            -&gt;addFilter(&quot;StringTrim&quot;)
            -&gt;addErrorMessage(&#039;Please Enter your Password&#039;)
            -&gt;setDecorators($decorators);

        $loginButton = new Zend_Form_Element_Submit(&#039;login&#039;);
        $loginButton
            -&gt;setValue(&#039;login&#039;);

        $this
            -&gt;addElements(
                array(
                    $username,
                    $password,
                    $loginButton
                )
            )
            -&gt;setMethod(&#039;post&#039;)
            -&gt;setName(&#039;loginForm&#039;)
            -&gt;addDecorator(
                array(&#039;mytag&#039; =&gt; &#039;HtmlTag&#039;), array(&#039;tag&#039; =&gt; &#039;div&#039;)
            )
            -&gt;removeDecorator(&#039;HtmlTag&#039;);

        $this-&gt;addStylesheet(&#039;/css/loginform.css&#039;,&#039;screen&#039;);
    }
}
</pre>
<p>And then as usual in you controller:</p>
<pre class="brush: php">
$form = new BinaryKitten_Form_LoginForm();
$this-&gt;view-&gt;form = $form;
</pre>
<p>and of course, echo it out in the view<br />
[sourcecoe lang="php"]<br />
echo $this->form;<br />
[/sourcecode]</p>
<p>And that&#8217;s it, Simple.<br />
Hopefully this will help someone out there</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/zend-framework/274-per-form-stylesheet-with-zend_form.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Keyz Plugin</title>
		<link>http://binarykitten.me.uk/dev/jq-plugins/259-jquery-keyz-plugin.html</link>
		<comments>http://binarykitten.me.uk/dev/jq-plugins/259-jquery-keyz-plugin.html#comments</comments>
		<pubDate>Wed, 24 Feb 2010 15:20:45 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[jQuery Plugins]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[keypress]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://binarykitten.me.uk/?p=259</guid>
		<description><![CDATA[The purpose of this plugin is to easily facilitate the end user to  create and hook key presses for their own use. Usually you would need to know what key links with which keycode etc.
Usage
It&#8217;s as easy as these steps:

Include jquery &#8211; either from CDN or local source
Include jquery.keyz.js
call the following within your document [...]]]></description>
			<content:encoded><![CDATA[<p>The purpose of this plugin is to easily facilitate the end user to  create and hook key presses for their own use. Usually you would need to know what key links with which keycode etc.</p>
<h3>Usage</h3>
<p>It&#8217;s as easy as these steps:</p>
<ol>
<li>Include jquery &#8211; either from CDN or local source</li>
<li>Include jquery.keyz.js</li>
<li>call the following within your document ready or after the item exists</li>
</ol>
<pre class="brush: javascript">
$(&#039;selector&#039;).keyz({
&quot;enter&quot;: function(ctl,sft,alt,event) {
alert(&#039;you pressed enter!&#039;);
}
});
</pre>
<p>this will hook the enter key and raise an alert when pressed.</p>
<p>If you  want to cancel the key either return false from the function or set the  value to false like so:</p>
<pre class="brush: javascript">
$(&#039;selector&#039;).keyz({
&quot;enter&quot;: function(ctl,sft,alt,event) {
return false;
}
});
</pre>
<p>OR</p>
<pre class="brush: javascript">
$(&#039;selector&#039;).keyz({
&quot;enter&quot;:false
});</pre>
<p>You can either use the key names in singular or in a grouping like so:</p>
<pre class="brush: javascript">
$(&#039;selector&#039;).keyz({
&quot;enter&quot;: function(ctl,sft,alt,event) {
/* single key */
return false;
},
&quot;F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12&quot;: function(ctl,sft,alt,event) {
/* mapped to all F-Keys */
return false;
}
});
</pre>
<p>Download jquery.keyz.js here: <a href="/keyzDemo/jquery.keyz.js">Full Source</a> &amp;&amp;  <a href="/keyzDemo/jquery.keyz.gc.js">Google Closure Compiled version</a></p>
<p>Visit the demo page here: <a href="/keyzDemo/">Full Source</a></p>
<h3>Planned Features</h3>
<ul>
<li>support for keypress chains .. passing a sequence of keys and an event firing upon completion</li>
<li><span style="text-decoration: line-through;">support for all three key states &#8211; presently only triggers on key down</span> &#8211; Added in 1.0.2</li>
<li>to add some <a href="http://paulirish.com/2010/duck-punching-with-jquery/" target="_blank">duck punching</a> to add the keyname to the event for the three standard events</li>
</ul>
<h3>Supported Keys</h3>
<p>The keys listed below are the current ones supported by the plugin.<br />
They also support the hyphenated name eg numpad-1 or in upper case like &#8220;F1&#8243; or &#8220;f1&#8243;</p>
<ul>
<li>enter</li>
<li>return</li>
<li>esc</li>
<li>escape</li>
<li>numerics</li>
<li>upper</li>
<li>lower</li>
<li>alphanumeric</li>
<li>tab</li>
<li>shift</li>
<li>alt</li>
<li>ctrl</li>
<li>f1</li>
<li>f2</li>
<li>f3</li>
<li>f4</li>
<li>f5</li>
<li>f6</li>
<li>f7</li>
<li>f8</li>
<li>f9</li>
<li>f10</li>
<li>f11</li>
<li>f12</li>
<li>caps</li>
<li>capslock</li>
<li>numlock</li>
<li>winflag</li>
<li>winkey</li>
<li>windows</li>
<li>scrolllock</li>
<li>left</li>
<li>up</li>
<li>right</li>
<li>down</li>
<li>volumeup</li>
<li>volumedown</li>
<li>menu</li>
<li>contextmenu</li>
<li>backspace</li>
<li>pause</li>
<li>break</li>
<li>pausebreak</li>
<li>pageup</li>
<li>pagedown</li>
<li>end</li>
<li>home</li>
<li>insert</li>
<li>del</li>
<li>delete</li>
<li>numpad0</li>
<li>numpad1</li>
<li>numpad2</li>
<li>numpad3</li>
<li>numpad4</li>
<li>numpad5</li>
<li>numpad6</li>
<li>numpad7</li>
<li>numpad8</li>
<li>numpad9</li>
<li>*</li>
<li>multiply</li>
<li>+</li>
<li>add</li>
<li>-</li>
<li>subtract</li>
<li>.</li>
<li>fullstop</li>
<li>decimal</li>
<li>/</li>
<li>divide</li>
<li>;</li>
<li>semicolon</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/jq-plugins/259-jquery-keyz-plugin.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Integrating PHP CodeSniffer with Activestate Komodo Edit</title>
		<link>http://binarykitten.me.uk/dev/219-integrating-php-codesniffer-with-activestate-komodo-edit.html</link>
		<comments>http://binarykitten.me.uk/dev/219-integrating-php-codesniffer-with-activestate-komodo-edit.html#comments</comments>
		<pubDate>Mon, 15 Feb 2010 02:34:26 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Activestate]]></category>
		<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Komodo]]></category>
		<category><![CDATA[Komodo Edit]]></category>
		<category><![CDATA[PHP_CodeSniffer]]></category>
		<category><![CDATA[Standards]]></category>

		<guid isPermaLink="false">http://binarykitten.me.uk/?p=219</guid>
		<description><![CDATA[I&#8217;ve recently been looking into standards of code and how they would apply to myself and my code. To enable this, I&#8217;ve recently installed PHP_CodeSniffer and for a few days been using this on the command line.. which by itself isn&#8217;t bad, though I really wanted to have something inside my editor of choice (happens [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been looking into standards of code and how they would apply to myself and my code. To enable this, I&#8217;ve recently installed PHP_CodeSniffer and for a few days been using this on the command line.. which by itself isn&#8217;t bad, though I really wanted to have something inside my editor of choice (happens to be Komodo Edit).<span id="more-219"></span></p>
<h2>Setting up Pear</h2>
<p>Since I will be using Pear to install the code sniffer we might as well cover that to start with.<br />
There are lots of tutorials out there with the aim of helping you to get pear installed no matter what the platform. I Will leave that job for them. What I will do is cover how to get it running easily with WampServer from <a href="http://www.wampserver.com/en/">http://www.wampserver.com/en/</a> Please do Note that this is all on a Windows Based machine</p>
<ol>
<li>Open a command prompt</li>
<li>Make a note of your php Directory&#8230; you will need this in a few places<br />
&#8220;WAMPDIR\bin\php\PHPVERSION&#8221;<br />
where WAMPDIR = the directory WampServer is installed to<br />
and PHPVERSION = php+version number..<br />
i&#8217;m using php 5.2.11 on wampserver so the location for me looks like this<br />
&#8220;D:\Wamp\bin\php\php5.2.11&#8243;</li>
<li>CD /D PHPDIR &#8211; where PHPDIR is the location you should have noted down in the last step</li>
<li>Type go-pear and watch as it installs</li>
<li>bring up the Advanced system properties</li>
<li>Environment Variables</li>
<li>Edit Path to add your php folder prefixed with a ;<br />
e.g. for my path was already c:\SharedLibs  so that became<br />
c:\SharedLibs;d:\wamp\bin\php\php5.2.11 &#8211; Close and save all settings</li>
</ol>
<h2>Installing PHP_CodeSniffer via Pear</h2>
<p>Now that I had pear installed I could use it to install PHP_CodeSniffer, this was a simple task with 1 line of code..<br />
<code>pear install PHP_Codesniffer</code> and that was it.. Actually I tell a small lie here, to make it work within the confines of other folders was to do as follows:</p>
<ol>
<li>Open the phpcs.bat file that resides in the php folder outlined above in notepad or similar editor</li>
<li>Change &#8220;./php.exe&#8221; to &#8220;php.exe&#8221;, save the file and close</li>
</ol>
<p>Now we are ready to run PHP_Codesniffer.</p>
<h2>Setting up Komodo Edit</h2>
<p>To start with, I use Komodo Edit for this, that is because that is what I use. I thoroughly recommend it over the likes of notepad++ etc mainly because of its feature set, and the way that it handles code completion from the project. But enough of all this, lets get down to creating a &#8220;run Command&#8221; for the active Tab/File in Komodo.</p>
<ol>
<li>Click Tools, then Run Commandin the R<span style="text-decoration: underline;">u</span>n box enter the following:</li>
<li><code>phpcs -n --standard=%(ask:Which Standard do you wish to use?:ZEND) --report=emacs "%F"</code>Check the <span style="text-decoration: underline;">A</span>dd to Toolbox optionToggle the More options So you can see the Advanced Options Panemake sure the &#8220;Run in&#8221; is set to Command Output TabCheck the &#8220;Parse Output with:&#8221; checkbox and enter the following in the select field:
<pre class="brush: text">
^(?P&lt;file&gt;.*):(?P&lt;line&gt;\d+):(?P&lt;column&gt;\d+):(?P&lt;content&gt;.*)
                     </pre>
</li>
<li>Check the &#8220;Show parsed output as a list&#8221; checkbox</li>
<li>Click the <span style="text-decoration: underline;">N</span>ew button to begin adding a envrionment variable</li>
<li>Set the &#8220;Variable Name&#8221; to PATH and the &#8220;Variable Value&#8221; to the location of PHP_Codesniffer &#8211; If you are following through this is the same as step 2 of &#8220;setting up pear&#8221;- then click ok</li>
<li>click <span style="text-decoration: underline;">R</span>un button &#8211; PHP_CodeSniffer will run and then will ask you for the standard you wish to check against .. by default It&#8217;s set to ZEND</li>
<li>Lastly right click the toolbox entry and bring up the properties. The Top left Text entry is the &#8220;nice name&#8221; for this. You can also assign keys to launch this command later</li>
</ol>
<p>Now you have successfully created a run Tool in Komodo that will run PHP_Codesniffer against the active file and will output the results in a nice list in the command output tab at the bottom panel. I chose the emacs output method as it was easier to get nice looking format without the \&#8221; escape sequence appearing in the &#8220;content&#8221;. The Reason for the regex and the list is that it will now allow you to double click and entry and it will jump to the right spot in the file.</p>
<p>I&#8217;ve also included a Komodo Package of 3 run time commands .. 1 for file, 1 for all files in the project and 1 for all files the directory shared with the currently active file. You can download them here: <a href="/CodeSniff.kpz">CodeSniff Package</a> &#8211; <strong>Recommended to Right-Click &#8211; Save Target as etc</strong> &#8211; This packages comes with predefined keystrokes </p>
<ul>
<li>CTRL+L,CTRL+S,CTRL+F to Codesniff the currently Active file</li>
<li>CTRL+L,CTRL+S,CTRL+P to Codesniff all files in the Project</li>
<li>CTRL+L,CTRL+S,CTRL+D to Codesniff all files in the Active File&#8217;s Directory</li>
</ul>
<p>I do hope that this will prove as useful for someone else as it has for me, comments are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/219-integrating-php-codesniffer-with-activestate-komodo-edit.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Word of the Day: &#8220;Spalooch&#8221;</title>
		<link>http://binarykitten.me.uk/general/buzzword-of-the-day/213-word-of-the-day-spalooch.html</link>
		<comments>http://binarykitten.me.uk/general/buzzword-of-the-day/213-word-of-the-day-spalooch.html#comments</comments>
		<pubDate>Sat, 30 Jan 2010 02:46:37 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Buzzword of the day]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://binarykitten.me.uk/?p=213</guid>
		<description><![CDATA[Yep another delightful new word you can add to your dictionaries.
Today&#8217;s Buzzword of the day is:
Spalooch
This is the sound that comes when you spill a liquid over the edge of its container onto your clothes.
When it happens, you have been Spalooched..  it is accidental and you can&#8217;t spalooch someone.
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Yep another delightful new word you can add to your dictionaries.<br />
Today&#8217;s Buzzword of the day is:</p>
<h2 style="text-align: center;">Spalooch</h2>
<p style="text-align: center;">This is the sound that comes when you spill a liquid over the edge of its container onto your clothes.</p>
<p style="text-align: center;">When it happens, you have been Spalooched..  it is accidental and you can&#8217;t spalooch someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/general/buzzword-of-the-day/213-word-of-the-day-spalooch.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Active Module Based Config with Zend Framework</title>
		<link>http://binarykitten.me.uk/dev/zend-framework/177-active-module-based-config-with-zend-framework.html</link>
		<comments>http://binarykitten.me.uk/dev/zend-framework/177-active-module-based-config-with-zend-framework.html#comments</comments>
		<pubDate>Mon, 04 Jan 2010 22:41:41 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[Component]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://binarykitten.me.uk/?p=177</guid>
		<description><![CDATA[I&#8217;ve recently taken to using Zend Framework for a project that I needed to bring up to date. I won&#8217;t go into the pros and cons of choosing a framework as there are many much more qualified people who have done a much better job of this subject than I would or could. So Instead [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently taken to using Zend Framework for a project that I needed to bring up to date. I won&#8217;t go into the pros and cons of choosing a framework as there are many much more qualified people who have done a much better job of this subject than I would or could. So Instead I bring to you How I managed to get Active Module Based Configuration within Zend Framework.</p>
<h2><strong>The Problem</strong></h2>
<p>The Concept I wanted to achieve was to have unique Configuration based upon the module that was active. The Issue with this is that the Bootstrap files and the _init functions for ALL modules are called with no bias as to which module is active. Thus if you created a 3 modules wanted to make menu alterations in one, those alterations will be applied to all. I also wanted to have a a system where if i added extra modules i could just add extra functions to the bootstrap file and it would work in a similar way.</p>
<p>With this in mind, I set about trying to figure out the solution.<br />
<span id="more-177"></span></p>
<h2><strong>Solution 1 &#8211; Failure</strong></h2>
<p>With the Idea that no-body is perfect, including myself. My 1st attempt ended in failure. This attempt was to modify/extend the Bootstrap class to add extra functions to the resources list.. In the end I couldn&#8217;t determine if the Module bootstrap was the active one. ok So Attempt 1 was a failure, onto the next</p>
<h2>Solution 2 &#8211; Success!</h2>
<p>A quick conversation with Matthew Weier O&#8217;Phinney (<a href="http://twitter.com/weierophinney">@weierophinney</a>) pointed me in the direction of Controller plugins and the routeShutdown method, as after the route had been finished which module was active would be able to be discerned.<br />
At this point I must apologise to Pieter Kokx ( @kokxie )  who I had a small disagreement with in the #zftalk channel. Pieter had done his best to point me down this route to start with, though being a stubborn mule I am refused to see the quality and precision of his comments.<br />
Thank you both for your help here.</p>
<p>The way that this works is that is scans the active modules bootstrap for functions starting with <span style="text-decoration: underline">activeInit</span> or <span style="text-decoration: underline">modulenameInit</span> just like the <a href="http://is.gd/64s1y">_init</a> functions but these would only be called if the module is active.<br />
I was successfully able to create the plugin and trigger the functions, unfortunately it was triggering/calling them in a static sense.. which meant that standard _init style code wouldn&#8217;t work. Luckily with a little digging in the source of the framework i found a storage of the modules and their initiated bootstrap classes. Lucky Me! So finally we call the methods within the right context.</p>
<p>So Here it is the Final Code, Please do comment, I learn from people as I hope that others can learn from me.</p>
<p>I&#8217;ve used the &#8220;Namespace&#8221; of BinaryKitten here. If you want to use a different &#8220;Namespace&#8221; Replace BinaryKitten with what you want.<br />
The &#8220;Namespace&#8221; allows for the use of the BinaryKitten folder within the Libray Folder.<br />
Remember the Controller Plugin should go in the right place for your application, if you are using the autoloader you can add the &#8220;Namespace&#8221; to be autoloaded via your application.ini</p>
<pre class="brush: text">
autoloadernamespaces[] = &quot;BinaryKitten&quot;
</pre>
<p>First off we have the Controller Plugin.<br />
This should go into the &#8220;Namespace&#8221; folder within the Library Folder and should be called ModuleConfig.php</p>
<pre class="brush: php">
&amp;amp;amp;lt;?php
&amp;amp;amp;lt;?php
class AonL_ModuleConfig extends Zend_Controller_Plugin_Abstract
{
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        $frontController = Zend_Controller_Front::getInstance();
        $bootstrap =  $frontController-&amp;amp;amp;gt;getParam(&#039;bootstrap&#039;);
        $activeModuleName = $request-&amp;amp;amp;gt;getModuleName();
        $moduleList = $bootstrap-&amp;amp;amp;gt;modules;

        $moduleInitName = strtolower($activeModuleName).&amp;amp;amp;quot;Init&amp;amp;amp;quot;;
        $moduleInitNameLength = strlen($moduleInitName);

        if (isset($moduleList[$activeModuleName])) {
            $activeModule = $moduleList[$activeModuleName];

            $bootstrapMethodNames = get_class_methods($bootstrap);
            foreach ($bootstrapMethodNames as $key=&amp;amp;amp;gt;$method) {
                $runMethod = false;
                $methodNameLength = strlen($method);
                if ($moduleInitNameLength &amp;amp;amp;lt; $methodNameLength &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;
                    $moduleInitName == substr($method, 0, $moduleInitNameLength)) {
                    call_user_func(array($bootstrap,$method));
                }
            }
        } else {
            $activeModule = $bootstrap;
        }

        $methodNames = get_class_methods($activeModule);
        foreach ($methodNames as $key=&amp;amp;amp;gt;$method) {
            $runMethod = false;
            $methodNameLength = strlen($method);
            if (10 &amp;amp;amp;lt; $methodNameLength &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; &#039;activeInit&#039; === substr($method, 0, 10)) {
                $runMethod = true;
            } elseif ($moduleInitNameLength &amp;amp;amp;lt; $methodNameLength &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;
                    $moduleInitName == substr($method, 0, $moduleInitNameLength)) {
                $runMethod = true;
            }
            if ($runMethod) {
                call_user_func(array($activeModule,$method));
            }
        }
    }
}
</pre>
<p>Next we need to make sure the Controller Plugin is loaded.<br />
We can do this in one of two ways. Either in the Application Bootstrap via an _init function</p>
<pre class="brush: php">
public function _initControllerPlugins()
{
    $plugin = Zend_Controller_Front::getInstance()-&amp;amp;amp;gt;registerPlugin(
        new BinaryKitten_ModuleConfig()
    );
}
</pre>
<p>*&#8211; Or &#8211;*</p>
<p>We can add a line to the application.ini</p>
<pre class="brush: text">
resources.frontController.plugins.BKModuleConfig = &quot;BinaryKitten_ModuleConfig&quot;
</pre>
<p>Finally some example init code from the module bootstrap.<br />
Please remember that the activeInit*() Functions need to be public for this to work properly</p>
<pre class="brush: php">
class Default_Bootstrap extends Zend_Application_Module_Bootstrap {
    public function activeInitMenus() {
        $layout = $this
                    -&amp;amp;amp;gt;bootstrap(&#039;layout&#039;)
                    -&amp;amp;amp;gt;getResource(&#039;layout&#039;);

        $view = $layout-&amp;amp;amp;gt;getView();
        $config = new Zend_Config_Xml(APPLICATION_PATH.&#039;/configs/navigation_default.xml&#039;,&amp;amp;amp;quot;menu&amp;amp;amp;quot;);
        $navigation = new Zend_Navigation($config);
        $view-&amp;amp;amp;gt;navigation($navigation);
    }
    public function activeInitDoSomethingElse() {
        /* some other code */
    }
    public function defaultInitSomething() {
    	/* more code */
    }
}
</pre>
<p>We can also add module inits to the application bootstrap like so:</p>
<pre class="brush: php">
    public function modulenameInitFunction() {
    	/* place code here */
    }
</pre>
<p>Where modulename is the lowercase version of the Modules name, eg if you have the Admin module, then you would use:</p>
<pre class="brush: php">
    public function adminInitFunction() {
    	/* place code here */
    }
</pre>
<p>Hopefully someone will find this code useful.</p>
<p>[ Edit January 5th 2010 ]<br />
Thanks to:<br />
	Matthew Weier O&#8217;Phinney for pointing out places for update.<br />
	Rob Allen (@Akrabat) for the info that the plugin could be loaded via the application.ini<br />
	Elizabeth Marie Smith and Matthew Turland for questioning the use of the Reflection.</p>
<ul>
<li>Updated the Bootstrap code to properly define the functions as Public</li>
<li>Removed the reflection as this wasn&#8217;t actually required any more.</li>
<li>Updated Post to make clean up the order of things and to properly designate that the BinaryKitten is the &#8220;Namespace&#8221;<br />
&#8220;Namespace&#8221; is used to reference that we&#8217;re not using PHP5.3 Namespaces, but the Namespaces within the Zend Framework.</li>
</ul>
<p>[ Edit January 11th 2010 ]<br />
Thanks to:<br />
	septem for pointing out a typo where i had $boostrap instead of $bootstrap<br />
	Gerard Roche for pointing out that by default, the default module doesn&#8217;t require a module bootstrap (in my code it has one)</p>
<ul>
<li>Updated to fix the typos</li>
<li>Added in a quick check to see if the module exists in the modules list of bootstraps</li>
<li>Removed the _ from the function name that it searches for, this should please the people who are adamant over the Zend Coding Standards</li>
<li>Added in the functionality to have $modulenameInit() functions as well in both active module bootstrap and the application bootstrap</li>
</ul>
<p>[ Edit February 13th 2010 ]<br />
Ran the code through codesniffer against the Zend Standard supplied.. updated so no errors found. 3 Warnings are left .. they are as follows:<br />
22 | WARNING | Line exceeds 80 characters; contains 83 characters<br />
35 | WARNING | Line exceeds 80 characters; contains 84 characters<br />
38 | WARNING | Line exceeds 80 characters; contains 83 characters<br />
Don&#8217;t think it&#8217;s worth the change for 3/4 characters </p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/zend-framework/177-active-module-based-config-with-zend-framework.html/feed</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Ada Lovelace day 2009 &#8211; @LornaJane #ALD09</title>
		<link>http://binarykitten.me.uk/personal/161-ada-lovelace-day-2009.html</link>
		<comments>http://binarykitten.me.uk/personal/161-ada-lovelace-day-2009.html#comments</comments>
		<pubDate>Tue, 24 Mar 2009 09:34:58 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[#ALD09]]></category>
		<category><![CDATA[Ada Lovelace]]></category>
		<category><![CDATA[admiration]]></category>
		<category><![CDATA[celebration]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=161</guid>
		<description><![CDATA[Today is Ada Lovelace day and as such, we are prompted to write about  someone we admire who is female and is involved in technology.
For my Post today I have chosen LornaJane. This stems from many reasons, which over the course of this post I hope to explain.

Ok As many of you know (and [...]]]></description>
			<content:encoded><![CDATA[<p>Today is <a href="http://www.findingada.com/" target="_blank">Ada Lovelace day</a> and as such, we are prompted to write about  someone we admire who is female and is involved in technology.</p>
<p>For my Post today I have chosen LornaJane. This stems from many reasons, which over the course of this post I hope to explain.</p>
<p><span id="more-161"></span></p>
<p>Ok As many of you know (and if you don&#8217;t then shame on you for not actually looking at the content :p ) I work with PHP and various other web related technologies on a daily basis (sometimes on a Nightly basis too ) and a few years ago I came across the <a href="http://www.phpwomen.org" target="_blank">PHP Women</a> group and started hanging around in their IRC channel. LornaJane was one of the people there that made me feel truely welcome.</p>
<p>After a while, the PHP UK Conference for 2008 came around and she prompted me to go, so I did. It was my first conference and I was extremely nervous, but I made it through and made some interesting acquaintances and new friends.</p>
<p>After this, she helped me get to grips with things and improve upon concepts and ideas I had, and also helped me gain confidence that maybe I wasn&#8217;t the silly girl for wanting to write code that had tainted before.</p>
<p>Later after another Conference, which she helped persuade and get me to, I had a crisis of confidence over some of the comments that people had left on the net in regard to it and myself. Lorna calmed me down and helped me see it in perspective.</p>
<p>So it&#8217;s for these reasons that I celebrate the PHP Woman LornaJane for all her good work within the community and for being someone that I would truely consider a friend.</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/personal/161-ada-lovelace-day-2009.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Chmod-ed to Windows hell and back</title>
		<link>http://binarykitten.me.uk/dev/php/159-php-chmod-ed-to-windows-hell-and-back.html</link>
		<comments>http://binarykitten.me.uk/dev/php/159-php-chmod-ed-to-windows-hell-and-back.html#comments</comments>
		<pubDate>Tue, 10 Mar 2009 21:05:22 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[files]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=159</guid>
		<description><![CDATA[Today has not been a good day.
With various things going wrong, I  was please that I had got the file upload code done for a site i&#8217;m working on. All I needed to do was make sure that the file had the right permissions and then edit it via GD (via an image editor [...]]]></description>
			<content:encoded><![CDATA[<p>Today has not been a good day.</p>
<p>With various things going wrong, I  was please that I had got the file upload code done for a site i&#8217;m working on. All I needed to do was make sure that the file had the right permissions and then edit it via GD (via an image editor class i have). Here&#8217;s where the trouble started..</p>
<p>I started off by chmoding the file to 777 and then trying to do the resize.. this threw an error with permissions.. so i looked at the file.. Read Only.. strange I thought.</p>
<p>Then I checked the folder and that had a weird green square instead of the checkmark in the checkbox. I tried to remove the read only attribute off of this and hte file.. and it kept coming back.. I went all around hte houses, trying all sorts of techniques .. to no avail.</p>
<p><a href="http://twitter.com/auroraeosrose">@auroraeosrose</a> in the PHPWomen IRC channel helped a lot as did Dreis.. (thanks muchly)..</p>
<p>After backing up the files and formatting the drive, to reinstalling the Apache/PHP/MySql stack I was no clearer to the answer as to why the file was always ending up with read only permissions..</p>
<p>Finally it came down to the 1 thing that I had overlooked.. the <a href="http://php.net/chmod">chmod</a> in the code .. the second parameter was 777. I thought this was correct. Aparrantly not. The second parameter of the chmod function requires an octal code.. thus prefixing the 777 with a 0 (zero) fixed the whole issue.</p>
<p>Boy did i really feel dumb today.</p>
<p>So to wrap up, remember to always pass a FOUR digit code through to chmod or face the annoyance and headache I got today.</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/php/159-php-chmod-ed-to-windows-hell-and-back.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySQL – Conditional Joins</title>
		<link>http://binarykitten.me.uk/dev/mysql/149-mysql-conditional-joins.html</link>
		<comments>http://binarykitten.me.uk/dev/mysql/149-mysql-conditional-joins.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 12:02:30 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[joins]]></category>
		<category><![CDATA[optional]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=149</guid>
		<description><![CDATA[For the most part I&#8217;ve used many JOINs in my queries since I leartn how to use them and what they were good for, I much prefer to use an Inner Join over the the Implied join of a WHERE statement.
For those who haven&#8217;t yet learnt about JOINs you might be using an implied join [...]]]></description>
			<content:encoded><![CDATA[<p>For the most part I&#8217;ve used many JOINs in my queries since I leartn how to use them and what they were good for, I much prefer to use an Inner Join over the the Implied join of a WHERE statement.</p>
<p>For those who haven&#8217;t yet learnt about JOINs you might be using an implied join in your queries even now&#8230; lets take this example:</p>
<pre class="brush: sql">
SELECT table1.field1,table2.field2
FROM table1,table2
WHERE table1.table2_id = table2.IDField
</pre>
<p>This is an Implied JOIN, you are telling MySQL to get the 2 fields from the 2 tables but only return the ones where the field in table1 is in the field in table2. This works, but using Joins we can improve it.</p>
<p>Ok,  Lets take the above example and apply the join mentality to it:</p>
<pre class="brush: sql">
SELECT table1.field1, table2.field2
FROM table1
INNER JOIN table2 on table1.table2_id = table2.IDField
</pre>
<p>This Links in only the rows that match the ON criteria which in theory should be less than the whole table, which again in theory should make the query faster.</p>
<p>Ok, now we have the JOIN theory out the way, we can get down to what this blog post is actually really all about, Conditional joins. Just Like the WHERE Clause in the SELECT statement you can use AND &amp; OR in the ON part of a JOIN. Usually it&#8217;s used to add more constraints to the join, but you can use it in interesting ways,</p>
<pre class="brush: sql">
SELECT table1.field1, table2.field2
FROM table1
INNER JOIN table2 on (table1.table2_id = table2.IDField) AND (table1.itemName = &#039;foo&#039;)
</pre>
<p>Only JOIN rows that have the matching ID and where the itemName from table1 is equal to foo;</p>
<pre class="brush: sql">
SELECT table1.field1, table2.field2
FROM table1
INNER JOIN table2 on ((table1.table2_id = table2.IDField) AND (table1.itemName = &#039;foo&#039;)) OR (table2.item = &#039;xx&#039;)
</pre>
<p>Only JOIN rows when the IDs are matching and the itemname is foo,  OR when the item in table2 is &#8216;xx&#8217;</p>
<p>Baring in mind that the more complicated you make it, the harder it will be to maintain IT still can be a great method of Reducing the amount of rows that need to be processed.</p>
<p>Hopefully this will help someone, if so or if you have anything to add/point out/criticise etc.. please do comment.. I Don&#8217;t Bite.</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/mysql/149-mysql-conditional-joins.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Conditional Updates</title>
		<link>http://binarykitten.me.uk/dev/mysql/144-mysql-conditional-updates.html</link>
		<comments>http://binarykitten.me.uk/dev/mysql/144-mysql-conditional-updates.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 01:31:58 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=144</guid>
		<description><![CDATA[Just a quick blog post in an update related way,
Recently i&#8217;ve needed to toggle multiple rows in a database from 1 value to 1 of possible 2 values dependant on the contents of a field on the row. I wasn&#8217;t sure if this was possible, so i asked in #PHPWomen IRC Channel and the general [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick blog post in an update related way,</p>
<p>Recently i&#8217;ve needed to toggle multiple rows in a database from 1 value to 1 of possible 2 values dependant on the contents of a field on the row. I wasn&#8217;t sure if this was possible, so i asked in #PHPWomen IRC Channel and the general response was that of &#8220;Don&#8217;t Know&#8221;.</p>
<p>So After a backup of the table in question, i decided to try it and see. After all, the worst it could do was just not work. So I tried the following:</p>
<pre class="brush: sql">
UPDATE `tble_name` SET `field1`=IF(`field2`=&#039;arbitrary_value&#039;,1,0) WHERE `field3`=&#039;other_value&#039;
</pre>
<p>And Voila updated all the rows exactly as needed.</p>
<p>So, It is possible to update all rows in a table, limited to a group and update value based upon a field matching a certain Value.<br />
So all in all MySQL For the WIN!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/mysql/144-mysql-conditional-updates.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin: Element Existence</title>
		<link>http://binarykitten.me.uk/dev/jq-plugins/131-jquery-plugin-element-existence.html</link>
		<comments>http://binarykitten.me.uk/dev/jq-plugins/131-jquery-plugin-element-existence.html#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:13:25 +0000</pubDate>
		<dc:creator>BinaryKitten</dc:creator>
				<category><![CDATA[jQuery Plugins]]></category>
		<category><![CDATA[exists]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://binarykitten.jkrswebsolutions.co.uk/?p=131</guid>
		<description><![CDATA[Just a Quick little snippet really..
Over at JqueryForDesigners.com  @rem mentioned about checking if an element exists or not, I&#8217;ve been doing this for some time using the following snippet:

jQuery.fn.exists = function() {
    return (this.length &#62; 0);
};

to use it you can now do this:

if ($(&#039;#elem&#039;).exists()) { /* do something */ }

Hope this [...]]]></description>
			<content:encoded><![CDATA[<p>Just a Quick little snippet really..</p>
<p>Over at JqueryForDesigners.com  <a href="http://twitter.com/rem">@rem</a> mentioned about <a href="http://jqueryfordesigners.com/element-exists/">checking if an element exists or not</a>, I&#8217;ve been doing this for some time using the following snippet:</p>
<pre class="brush: javascript">
jQuery.fn.exists = function() {
    return (this.length &gt; 0);
};
</pre>
<p>to use it you can now do this:</p>
<pre class="brush: javascript">
if ($(&#039;#elem&#039;).exists()) { /* do something */ }
</pre>
<p>Hope this is helpful to some people</p>
]]></content:encoded>
			<wfw:commentRss>http://binarykitten.me.uk/dev/jq-plugins/131-jquery-plugin-element-existence.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
