<?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>dom111.co.uk &#187; Coding</title>
	<atom:link href="http://www.dom111.co.uk/blog/tag/coding/feed" rel="self" type="application/rss+xml" />
	<link>http://www.dom111.co.uk/blog</link>
	<description>Move along. Nothing to see here.</description>
	<lastBuildDate>Wed, 26 Oct 2011 16:37:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jQuery serializeObject 0.1</title>
		<link>http://www.dom111.co.uk/blog/coding/jquery-serializeobject-0-1/283</link>
		<comments>http://www.dom111.co.uk/blog/coding/jquery-serializeobject-0-1/283#comments</comments>
		<pubDate>Thu, 31 Mar 2011 22:37:47 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[formToObject]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[post data]]></category>
		<category><![CDATA[serializeObject]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=283</guid>
		<description><![CDATA[I found myself in a situation recently where I wanted to have access to variables that would have been posted, in a the same structure as if the form had been posted and returned the JSON, using this jQuery plugin and Douglas Crockford&#8217;s JSON library, I think I&#8217;ve done it! You can download the script [...]]]></description>
			<content:encoded><![CDATA[<p>I found myself in a situation recently where I wanted to have access to variables that would have been posted, in a the same structure as if the form had been posted and returned the JSON, using this jQuery plugin and <a href="https://github.com/douglascrockford/JSON-js">Douglas Crockford&#8217;s JSON library</a>, I think I&#8217;ve done it!</p>
<p>You can <a href="/files/jquery-serializeObject/jquery.serializeObject-0.1.tar.gz">download the script here</a> and there&#8217;s <a href="/files/jquery-serializeObject">a demo here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/jquery-serializeobject-0-1/283/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropdownify &#8211; Minimal effort dropdown</title>
		<link>http://www.dom111.co.uk/blog/coding/dropdownify-minimal-effort-dropdown/218</link>
		<comments>http://www.dom111.co.uk/blog/coding/dropdownify-minimal-effort-dropdown/218#comments</comments>
		<pubDate>Wed, 27 Jan 2010 12:19:38 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[drop-down]]></category>
		<category><![CDATA[drop-down menu]]></category>
		<category><![CDATA[drop-down navigation]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[top nav]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=218</guid>
		<description><![CDATA[So recently I was asked to change a navigation style of an existing site to drop-down menus. Simple, I thought, just use one of the many existing drop-down plugins. I tried many, but most seemed to use hardcoded styles and I had a few problems (some of which I encountered again, writing this). So I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>So recently I was asked to change a navigation style of an existing site to drop-down menus.</p>
<p>Simple, I thought, just use one of the many existing drop-down plugins. I tried many, but most seemed to use hardcoded styles and I had a few problems (some of which I encountered again, writing this).</p>
<p>So I&#8217;ve made this, I think it&#8217;s fairly robust, but I&#8217;m sure there&#8217;ll be problems with embedded objects (flash) and select boxes (in <= IE6), but for my needs, it sufficed, so I thought I'd share, in case anyone else needs a simple script to manage drop-downs.</p>
<p>To use, create a nest of elements like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;ul id=&quot;top&quot;&gt;
  &lt;li&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;</pre></div></div>

<p>or something similar (any elements, <strong><em>should</em></strong> work) and call:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// jQuery:</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul#top'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dropdownify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// mootools</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dropdownify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Which should create a simple drop-down.</p>
<p>There are a couple of examples, <a href="/files/dropdownify/jquery">one for jQuery</a> and <a href="/files/dropdownify/mootools">one for mootools</a>, and the files can downloaded <a href="/files/dropdownify/jquery.dropdownify-0.1.tar.gz">here</a> and <a href="/files/dropdownify/dropdownify-0.1.tar.gz">here</a>.</p>
<p>I did encounter a problem with IE, mainly due to z-index faults, so with HTML code like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;nav-wrapper&quot;&gt;
  &lt;ul id=&quot;top&quot;&gt;
    &lt;li&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;</pre></div></div>

<p>I used the following CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div.nav-wrapper<span style="color: #00AA00;">,</span>
div<span style="color: #6666ff;">.nav-wrapper</span> ul<span style="color: #00AA00;">,</span>
div<span style="color: #6666ff;">.nav-wrapper</span> ul li <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">static</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/dropdownify-minimal-effort-dropdown/218/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP: Components, redirect fail (On my part&#8230;)</title>
		<link>http://www.dom111.co.uk/blog/coding/cakephp-components-redirect-fail-on-my-part/171</link>
		<comments>http://www.dom111.co.uk/blog/coding/cakephp-components-redirect-fail-on-my-part/171#comments</comments>
		<pubDate>Wed, 26 Aug 2009 19:58:46 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[epic fail]]></category>
		<category><![CDATA[lessons learned]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[redirect loses id]]></category>
		<category><![CDATA[redirect losing id]]></category>
		<category><![CDATA[redirect strips id]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=171</guid>
		<description><![CDATA[I&#8217;ve been working on a CakePHP project lately and created a small component which was only needed in one of my controllers: class CounterComponent extends Component &#123; var $components = array&#40; 'Session' &#41;; &#160; function i&#40;&#41; &#123; if &#40;$this-&#62;Session-&#62;check&#40;'Counter.i'&#41;&#41; &#123; $i = &#40;$this-&#62;Session-&#62;read&#40;'Counter.i'&#41; + 1&#41;; &#160; &#125; else &#123; $i = 0; &#125; &#160; $this-&#62;Session-&#62;write&#40;'Counter.i', [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a <a href="http://www.cakephp.org/">CakePHP</a> project lately and created a small component which was only needed in one of my controllers:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> CounterComponent <span style="color: #000000; font-weight: bold;">extends</span> Component <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$components</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'Session'</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> i<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Counter.i'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Counter.i'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Counter.i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">function</span> clear<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><span style="color: #004000;">Session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Counter.i'</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><span id="more-171"></span>It simply kept track of a number over the life of the current session and incremented it each time it was accessed. I did&#8217;t think it would interfere in my other controllers, and it didn&#8217;t until I tried to perform a simple redirect later on in the app:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">function</span> edit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// process it</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Customer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Customer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'controller'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'customers'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$id</span>
      <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <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><span style="color: #004000;">data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Customer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span>
      <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_defined_vars</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>That code seemed simple enough, but each and every time it was run, I&#8217;d be sent to <code>/customers/edit</code>, instead of <code>/customers/view/1</code>.</p>
<p>WTF? Cake is losing my <code>id</code>s?</p>
<p>So I tried changing the redirect to a string:</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;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/customers/view/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>No difference, still redirects to <code>/customers/edit</code>. Ok fine. Lets try a full URL:</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;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.google.co.uk/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Serisouly. Still? All this happened over a series of a couple of days, each session of <del>coding</del><ins>banging my head against a brick wall</ins> leaving me more frustrated. I got mad I created a <code>TestsController</code> with an action <code>test</code> which exhibited the same behaviour&#8230; (But only after I&#8217;d moved everything into the <code>AppController</code>, whilst franticly trying everything&#8230; *sigh*)</p>
<p>After many visits to the <a href="http://book.cakephp.org/">CakePHP documentation</a> I decided to re-investigate the <a href="http://api.cakephp.org/view_source/controller/#line-536">source code</a> and see if I had missed anything. The <code lang="php">Controller::redirect()</code> function contains this code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Component</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">beforeRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</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: #b1b100;">return</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$resp</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;">$resp</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</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: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resp</span><span style="color: #339933;">,</span> EXTR_OVERWRITE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$resp</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$resp</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>&#8220;But that&#8217;s fine!&#8221;, I thought, &#8220;I don&#8217;t even have a <code>beforeRedirect()</code> function in my component, and surely the class I&#8217;m extending will just return <code>null</code>.&#8221; Oh dear. Assumption. <a href="http://api.cakephp.org/view_source/component/#line-139">There it is</a>, done now.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Component::beforeRedirect</span>
	<span style="color: #000000; font-weight: bold;">function</span> beforeRedirect<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exit</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$response</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: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_primary <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$component</span> <span style="color: #339933;">=&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_loaded<span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$component</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enabled</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$component</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'beforeRedirect'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$resp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$component</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">beforeRedirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #000088;">$exit</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;">$resp</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: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$resp</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Crap. It returns an empty array, which the <code>redirect()</code> function will use because it isn&#8217;t <code>null</code>, which will redirect to the current controller/action but strip out the <code>id</code>.</p>
<p><strong>Lesson</strong>: Always, <strong><em>ALWAYS</em></strong>, create a base component to extend, or, alternatively, just <a href="http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components">read the fricking manual properly</a>.</p>
<p><strong>TL;DR</strong>: I failed at creating a CakePHP component. Fix: <code>class MyComponent extends Object {}</code> instead of <code>class MyComponent extends Component {}</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/cakephp-components-redirect-fail-on-my-part/171/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JSS 0.2 &#8211; Nested CSS update</title>
		<link>http://www.dom111.co.uk/blog/coding/jss-0-2-nested-css-update/118</link>
		<comments>http://www.dom111.co.uk/blog/coding/jss-0-2-nested-css-update/118#comments</comments>
		<pubDate>Tue, 28 Jul 2009 22:33:08 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[jss]]></category>
		<category><![CDATA[nested css]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=118</guid>
		<description><![CDATA[So I thought I&#8217;d update the JSS script I wrote previously with a few changes I&#8217;ve been thinking about for a while. The primary reason for the update is to add a new &#8216;non-CSS&#8217; property of &#8216;include&#8217;. This property allows you to include styles that have already been defined in the current class. For example, [...]]]></description>
			<content:encoded><![CDATA[<p>So I thought I&#8217;d update the JSS script I wrote previously with a few changes I&#8217;ve been thinking about for a while.</p>
<p>The primary reason for the update is to add a new &#8216;non-CSS&#8217; property of &#8216;include&#8217;. This property allows you to include styles that have already been defined in the current class.<span id="more-118"></span></p>
<p>For example, if you had a stylesheet that looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.<span style="color: #993333;">bold</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.important</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You could rewrite this using:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">JSS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;.bold&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;font-weight&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;bold&quot;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #3366CC;">&quot;.important&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;include&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;.bold&quot;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Which I know you shouldn&#8217;t really do, and yes, it probably does go against the whole point of CSS, but I&#8217;m sure it&#8217;ll be useful in some situation at some point&#8230; No? Well it was interesting making it anyway.</p>
<p>Other minor updates are a PHP version so you can write nested stylesheets and output minified CSS all server-side and a bunch of HTML colour names that are actually shorter than the 6 digit hex codes.</p>
<p>I might work on doing other languages if I fancy the practice&#8230; Probably make a CSS to JSS conversion script first though&#8230;</p>
<p>You can see the <a href="/files/jss/0.2/"> updated demo page here</a>, or just <a href="/files/jss/jss-0.2.tar.gz">download the files here and have a look for yourself</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/jss-0-2-nested-css-update/118/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mod-framework: PHP, light and easy</title>
		<link>http://www.dom111.co.uk/blog/rambles/mod-framework-php-light-and-easy/39</link>
		<comments>http://www.dom111.co.uk/blog/rambles/mod-framework-php-light-and-easy/39#comments</comments>
		<pubDate>Thu, 13 Nov 2008 14:16:45 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rambles]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[convention over configuration]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[model view controller]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=39</guid>
		<description><![CDATA[I know there&#8217;s already infinite PHP framework out there, trying to be rails; and most of them are doing it really well, I just feel that none of them completely embrace the simplicity of convention over configuration, so I&#8217;m trying to build one that ticks all the boxes. It&#8217;s pretty simple so far, and is [...]]]></description>
			<content:encoded><![CDATA[<p>I know there&#8217;s already infinite PHP framework out there, trying to be rails; and most of them are doing it really well, I just feel that none of them completely embrace the simplicity of convention over configuration, so I&#8217;m trying to build one that ticks all the boxes.</p>
<p>It&#8217;s pretty simple so far, and is only a few hundred KB, but I think it&#8217;s got some cool features, and maybe even potential.</p>
<p>Like the other stuff it&#8217;s under a Creative-Commons SA license and can be found at:</p>
<p><a href="http://mod-framework.googlecode.com/">http://mod-framework.googlecode.com/</a>.</p>
<p>Any opinions, suggestions, contributions would be gratefully received.</p>
<p>Current functionality:</p>
<p>Model-View-Controller system<br />
MySQL support (using a modified version of the DB class from earlier)<br />
script/server implementation in PHP<br />
Helper association, so if you create a PageHelper class for your Pages controller all the functions will automatically be made &#8216;global&#8217; (accessible view functionname() instead of Helper::functionname())<br />
Includes mootools in the htdocs folder</p>
<p>The DB doesn&#8217;t work quite how I would have imagined it to (well, with PHP 5.3 it might&#8230; but I haven&#8217;t got it yet&#8230;) so currently any models are added to $GLOBALS[] so that for a Page model, $GLOBALS['Page']-&gt;find_by_name(&#8216;dom&#8217;), etc would work.</p>
<p>There&#8217;s probably some other stuff in there too&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/rambles/mod-framework-php-light-and-easy/39/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL backup script</title>
		<link>http://www.dom111.co.uk/blog/coding/mysql-backup-script/30</link>
		<comments>http://www.dom111.co.uk/blog/coding/mysql-backup-script/30#comments</comments>
		<pubDate>Thu, 16 Oct 2008 08:45:30 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=30</guid>
		<description><![CDATA[I&#8217;ve recently been learning more and more about bash scripting and the cool functions and features that are included, that i&#8217;ll probably never use&#8230; I recently had to set up a cron to backup all MySQL databases but I didn&#8217;t want them in one huge file. So I&#8217;ve written a little script, that is probably [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been learning more and more about bash scripting and the cool functions and features that are included, that i&#8217;ll probably never use&#8230;</p>
<p>I recently had to set up a cron to backup all MySQL databases but I didn&#8217;t want them in one huge file.</p>
<p>So I&#8217;ve written a little script, that is probably not entirely efficient, but serves it&#8217;s purpose for us:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># get todays date</span>
<span style="color: #007800;">DATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%F&quot;</span><span style="color: #000000; font-weight: bold;">`</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># go to the backup directory</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>mysql
&nbsp;
<span style="color: #666666; font-style: italic;"># export the databases, each to it's own file</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># the first echo is sent to mysql, so we're basically echoing SHOW DATABASES; to mysql</span>
<span style="color: #666666; font-style: italic;"># then we're chopping off the first line (sed 1d) and passing the remaining input to</span>
<span style="color: #666666; font-style: italic;"># xargs which accepts \n or space delimited arguments as a list and echo's out the</span>
<span style="color: #666666; font-style: italic;"># string mysqldump -u &lt;username&gt; -p&lt;password&gt; % &gt; %.sql (replacing % with the name) to</span>
<span style="color: #666666; font-style: italic;"># /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SHOW DATABASES;&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mysql <span style="color: #660033;">-u</span> <span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span> -p<span style="color: #000000; font-weight: bold;">&lt;</span>password<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> 1d <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">--replace</span>=<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;mysqldump -u &lt;username&gt; -p&lt;password&gt; % &gt; %.sql&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># compress the backups</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> czf mysql_backup_<span style="color: #007800;">$DATE</span>.tar.gz <span style="color: #000000; font-weight: bold;">*</span>.sql
&nbsp;
<span style="color: #666666; font-style: italic;"># remove the large .sql files</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">*</span>.sql</pre></div></div>

<p>This was tested on a SuSE 11 server, might need some tweaking on other dists.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/mysql-backup-script/30/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>submitEvents &#8211; Javascript form submission handler</title>
		<link>http://www.dom111.co.uk/blog/coding/submitevents-javascript-form-submission-handler/20</link>
		<comments>http://www.dom111.co.uk/blog/coding/submitevents-javascript-form-submission-handler/20#comments</comments>
		<pubDate>Thu, 14 Aug 2008 01:06:46 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[onsubmit]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=20</guid>
		<description><![CDATA[Something that I seem to be doing a lot lately, is writing a handler for processing the submission of a form, and since mootools is the JS framework of choice, I&#8217;ve written this little class that handles the onsubmit of a form and adds some useful features. Confirmation &#8211; Provides an Ok, Cancel input box [...]]]></description>
			<content:encoded><![CDATA[<p>Something that I seem to be doing a lot lately, is writing a handler for processing the submission of a form, and since mootools is the JS framework of choice, I&#8217;ve written this little class that handles the onsubmit of a form and adds some useful features.</p>
<ul>
<li>Confirmation &#8211; Provides an Ok, Cancel input box before proceeding further</li>
<li>Submit Button &#8211; Disable and change the text on a submit button</li>
<li>Information Div &#8211; Display a div that lets the user know something is happening</li>
<li>Undo &#8211; Undo the changes (re-enable a previously disabled submit button, change the information div) that have been carried out by the class</li>
<li>AJAX &#8211; Submit the form using AJAX instead of the &#8216;old fashioned&#8217; way</li>
</ul>
<p>All these should be easily implemented using the class.</p>
<p>Examples are provided in examples.html.</p>
<p>As previously, this work is released under the creative commons share alike license.</p>
<p><del datetime="2008-08-14T13:30:28+00:00"><a href="http://www.dom111.co.uk/files/submitEvents/submitEvents_0.1.zip">Download submitEvents 0.1 (31.9k) (Includes mootools 1.2)</a></del></p>
<p>Edit: I really do dislike internet exploder&#8230; The above version failed in IE6 (mootools&#8217; form.toQueryString() function). I&#8217;ve updated the code to 0.11 which can be found here:</p>
<p><a href="http://www.dom111.co.uk/files/submitEvents/submitEvents_0.11.zip">submitEvents 0.11 (32.8k) (Includes mootools 1.2)</a></p>
<p>Edit 2: Ok, so my hatred for IE, although deserved, was unnecessary in this situation&#8230;</p>
<p>I&#8217;ve updated the code to use mootools .bind(this) on the ajax onComplete function, this fixed the main problem with IE6 and makes the code look much cleaner. Also the examples file is now PHP instead of static HTML and returns a var_dump of $_POST when the form is submitted.</p>
<p>PS. This will be the final update to this post!</p>
<p><a href="http://www.dom111.co.uk/files/submitEvents/submitEvents_0.2.zip">submitEvents 0.2 (32.3k) (Includes mootools 1.2)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/submitevents-javascript-form-submission-handler/20/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DB</title>
		<link>http://www.dom111.co.uk/blog/coding/db/8</link>
		<comments>http://www.dom111.co.uk/blog/coding/db/8#comments</comments>
		<pubDate>Wed, 23 Jul 2008 22:50:01 +0000</pubDate>
		<dc:creator>dom111</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.dom111.co.uk/blog/?p=8</guid>
		<description><![CDATA[Here&#8217;s a little script I&#8217;ve wanted to make for a while, but have only just finally got the motivation to work on. It&#8217;s a lightweight Database wrapper with functions similar to Ruby on Rails&#8217; ActiveRecord. When I discovered the __call() method I wanted to make my own version in PHP, so here it is! It [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little script I&#8217;ve wanted to make for a while, but have only just finally got the motivation to work on.</p>
<p>It&#8217;s a lightweight Database wrapper with functions similar to Ruby on Rails&#8217; ActiveRecord.</p>
<p>When I discovered the __call() method I wanted to make my own version in PHP, so here it is!</p>
<p>It supports most basic functions, all based on the MySQL set of PHP functions, no other wrapper is required (PEAR etc.). There is not (yet?) any automatic mysql_real_escape_string or anything, although that could easily be added if required, my assumption is you&#8217;ve done that kind of thing already before passing anything to it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DB<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysql://username:password@server:port/database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$people</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'people'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$companies</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'companies'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$company</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$company</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find_by_name_like</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%test%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$person</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$people</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Dom'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'company_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$company</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'created_date'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$people</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">lastId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$people</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Dom</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #000088;">$dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Dom</span>
&nbsp;
<span style="color: #000088;">$dom</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$person</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_users</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find_by_created_date_before</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1 hour ago'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_users</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// loop through all the users with a create date more than 1 hour ago</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$company</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">company_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// and delete any that don't have a company associated with them</span>
    <span style="color: #000088;">$people</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</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></td></tr></table></div>

<p>It&#8217;s only a first draft, so any comments, questions or pointing out any typo&#8217;s in the code, (yeah, there are likely to be a few&#8230;) would be muchly appreciated.</p>
<p>This work is free under the <a href="http://creativecommons.org/licenses/by-sa/2.0/uk/">Creative Commons Share Alike 2.0 license</a>.</p>
<p>Download:</p>
<p><a href="/files/DB/DB_0.1.tar.gz" title="Download DB_01.tar.gz">DB_0.1.tar.gz (4.84Kb)</a></p>
<p>Edit: Think next on my list is TextMate syntax highlighting and maybe the non-default template&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dom111.co.uk/blog/coding/db/8/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

