<?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>woblog &#187; php</title>
	<atom:link href="http://www.whiteoctober.co.uk/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.whiteoctober.co.uk/blog</link>
	<description>great stuff about the web</description>
	<lastBuildDate>Mon, 05 Dec 2011 16:53:15 +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>How to test UTF-8 email subject lines in Symfony</title>
		<link>http://www.whiteoctober.co.uk/blog/2011/01/25/how-to-test-utf-8-email-subject-lines-in-symfony/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2011/01/25/how-to-test-utf-8-email-subject-lines-in-symfony/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 13:23:50 +0000</pubDate>
		<dc:creator>smotraghi</dc:creator>
				<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=691</guid>
		<description><![CDATA[One of our clients needs to send emails with UTF-8 subject lines. Swift Mailer, which Symfony uses, makes this easy to do, but writing functional tests for it is another story.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">
<p>(crossposted from Sebastian&#8217;s <a href="http://blog.motraghi.us/2011/01/how-to-test-utf-8-email-subject-lines-in-symfony/">personal blog</a>)</p>
<p>One of our clients needs to send emails with UTF-8 subject lines. Swift Mailer, which Symfony uses, makes this easy to do, but writing functional tests for it is another story. The problem is that, if non-ASCII characters are present in the subject line, Swift Mailer encodes them as required by <a href="http://datatracker.ietf.org/doc/rfc2047/">RFC 2047</a> – for example, a string like &#8220;Transformación&#8221; turns into &#8220;=?utf-8?Q?Transformaci=C3=B3n?=&#8221;. How do we know that this is the right subject line?</p>
<p>There&#8217;s no immediately-available &#8220;convert this into a RFC 2047-compliant subject line&#8221; function, but we can get around this by making use of <code>Swift_Message-&gt;toString</code> and some choice preg functions.</p>
<p>First, create a dummy message containing the appropriate header. <code>Swift_Message-&gt;toString()</code> will contain our encoded header:</p>
<p><script src="https://gist.github.com/794680.js?file=gistfile1.php"></script> Next, we have to extract our encoded header – I&#8217;ve used <code>preg_match()</code> and a fairly simple regex.  <script src="https://gist.github.com/794680.js?file=gistfile2.php"></script></p>
<p>Finally, now that the encoded header has been extracted, we need only wrap it in <code>preg_quote()</code> (because <code>checkHeader()</code> uses regex syntax) and test away.</p>
<p><script src="https://gist.github.com/794680.js?file=gistfile3.php"></script></p>
<p>Voila – now we can be confident that our test script can deal with Unicode email subjects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2011/01/25/how-to-test-utf-8-email-subject-lines-in-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stored functions with Symfony and Doctrine</title>
		<link>http://www.whiteoctober.co.uk/blog/2011/01/05/stored-functions-with-symfony-and-doctrine/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2011/01/05/stored-functions-with-symfony-and-doctrine/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 09:17:12 +0000</pubDate>
		<dc:creator>Rich</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=665</guid>
		<description><![CDATA[A Symfony project I’m working on currently requires a couple of MySQL stored functions to be available. In the interests of making the code I write reusable in future, some of it has been moved into a plugin, but this code relies on a couple of stored functions being available.]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://www.symfony-project.org/">Symfony</a> project I&#8217;m working on currently requires a couple of <a href="http://www.mysql.com/">MySQL</a> stored functions to be available.  In the interests of making the code I write reusable in future, some of it has been moved into a plugin, but this code relies on a couple of stored functions being available.  As this code is also unit tested, I needed to make sure the stored functions were available on database drop-and-load which happens in the unit test bootstrap (via the <a href="http://www.doctrine-project.org/">Doctrine</a> tasks provided).</p>
<p>First of all, my stored functions are in separate .sql files in my plugin&#8217;s <code>data/sql/</code> directory in the interests of following convention within the project&#8217;s directory structure.</p>
<p>Secondly, in myPlugin/config/MyPluginConfiguration.class.php file, I have the following for the <code>initialize()</code> method.:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> initialize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;zz_myplugin_dir&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRootDir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatcher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;command.post_command&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'initializeStoredFuncs'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We listen for the <code>command.post_command</code> event which we can then check to see if it&#8217;s a Doctrine insert-sql task being run.  We also check to see if the function already exists before attempting to create it &#8211; if not, then carry on.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> initializeStoredFuncs<span style="color: #009900;">&#40;</span>sfEvent <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  static <span style="color: #000088;">$doneConfig</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$doneConfig</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Already done it.</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSubject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> instanceof sfDoctrineInsertSqlTask<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;">// Not inserting any SQL. No point continuing</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Get database connection</span>
  <span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> Doctrine_Manager<span style="color: #339933;">::</span><span style="color: #004000;">connection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Configure function 1</span>
  <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">addStoredRoutine</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;myFuncName1&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;myFuncName1.sql&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Configure function 2</span>
  <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">addStoredRoutine</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;someOtherFunc&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;someOtherFunc.sql&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Set config completed flag for later</span>
  <span style="color: #000088;">$doneConfig</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* Adds a stored procedure into the database
*
* @param string $con Connection to use
* @param string $routineName Routine name
* @param string $routineFile Filename inside our [plugin dir]/data/sql/
*/</span>
protected static <span style="color: #000000; font-weight: bold;">function</span> addStoredRoutine<span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #339933;">,</span> <span style="color: #000088;">$routineName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$routineFile</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$con</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dsn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;dsn&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/dbname=([^;]+)[;]?/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dsn</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dbname</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT COUNT(*) AS c FROM information_schema.routines WHERE routine_name = '<span style="color: #006699; font-weight: bold;">{$routineName}</span>' AND routine_schema = '<span style="color: #006699; font-weight: bold;">{$dbname}</span>'&quot;</span><span style="color: #339933;">;</span>
  try
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$con</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDbh</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// No database available - can't carry on</span>
    <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$resultSet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$resultSet</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Create the function</span>
    <span style="color: #000088;">$sqlRoutine</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;zz_myplugin_dir&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/data/sql/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$routineFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$con</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDbh</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sqlRoutine</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;m not a massive fan of the way the database name has been retrieved but it works for now :-) I&#8217;m pretty sure there&#8217;s a neater way of accomplishing the above too, but this is working consistently and allows the stored functions to become part of a plugin, so that if the plugin is removed at a later date, then any subsequent database builds will not have unnecessary routines hanging around.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2011/01/05/stored-functions-with-symfony-and-doctrine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple shorten url using bit.ly and php</title>
		<link>http://www.whiteoctober.co.uk/blog/2009/11/23/simple-shorten-url-using-bit-ly-and-php/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2009/11/23/simple-shorten-url-using-bit-ly-and-php/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 14:10:11 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[bitly]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=415</guid>
		<description><![CDATA[Inspired by the simple tweet to twitter function by Fabian Potencier I have built a stupidly simple url shorter for bit.ly. Something you are probably going to want to do if you are sending tweets via PHP. function shorten($url, $login, $apikey) { $api_url = "http://api.bit.ly/shorten?version=2.0.1&#38; longUrl=".urlencode($url)."&#38;login=".$login."&#38; apiKey=".$apikey; $ret = file_get_contents($api_url); $data = json_decode($ret); if($data instanceof [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by the simple <a href="http://fabien.potencier.org/article/20/tweeting-from-php">tweet</a> to <a href="http://twitter.com">twitter</a> function by <a href="http://fabien.potencier.org">Fabian Potencier</a> I have built a stupidly simple url shorter for <a href="http://bit.ly">bit.ly</a>. Something you are probably going to want to do if you are sending tweets via PHP.</p>
<pre><code>function shorten($url, $login, $apikey)
{
  $api_url = "http://api.bit.ly/shorten?version=2.0.1&amp;
                    longUrl=".urlencode($url)."&amp;login=".$login."&amp;
                    apiKey=".$apikey;
  $ret = file_get_contents($api_url);
  $data = json_decode($ret);
  if($data instanceof stdClass &amp;&amp; property_exists($data, "errorCode") &amp;&amp; $data-&gt;errorCode==0)
  {
    foreach($data-&gt;results as $result)
    {
      if(isset($result-&gt;shortUrl))
      {
        return $result-&gt;shortUrl;
      }
    }
  }
  return $url;
}</code></pre>
<p>In the application where I am using this function I have defined the login name and api key as constants, so you can do away with 2 function calls.</p>
<p>Also handily it returns the original url if <a href="http://bit.ly">bit.ly</a> fails.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2009/11/23/simple-shorten-url-using-bit-ly-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t be afraid to NOT use the ORM&#8230;</title>
		<link>http://www.whiteoctober.co.uk/blog/2009/10/16/dont-be-afraid-to-not-use-the-or/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2009/10/16/dont-be-afraid-to-not-use-the-or/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 15:06:03 +0000</pubDate>
		<dc:creator>Rich</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[Web technologies]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=353</guid>
		<description><![CDATA[I&#8217;ve been racking my brains the past couple of days with a Doctrine issue within a Symfony project. I was constructing a bank statement-esque page, which iterated over a &#8220;StatementEntry&#8221; table and displayed the results. Entries could either be of model Type A or model Type B, with the relevant model ID stored in the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been racking my brains the past couple of days with a <a title="Doctrine" href="http://www.doctrine-project.org/">Doctrine</a> issue within a <a title="Symfony" href="http://www.symfony-project.org/">Symfony</a> project.  I was constructing a bank statement-esque page, which iterated over a &#8220;StatementEntry&#8221; table and displayed the results.  Entries could either be of model Type A or model Type B, with the relevant model ID stored in the StatementEntry table.  The relationship was defined by a &#8220;type&#8221; column.  Type A and B models also had other relationships after the initial one.</p>
<p>The problem I discovered was that obviously Doctrine didn&#8217;t know what the conditional relationships were, since it was dependant on the type column.  I researched some different approaches:</p>
<ol>
<li> <strong>Doctrine&#8217;s RawSql</strong>
<p>This approach worked for generating the correct SQL query without a problem, but the issue then arose of how Doctrine could hydrate the result set.  Answer was &#8211; it couldn&#8217;t :-) Well, I lie &#8211; I could use Doctrine::HYDRATE_SCALAR but I had issues with other related models, where I was joining to a table twice but under different aliases, which failed, since the scalar hydration would override earlier joins on the same table.</li>
<li> <strong>Column aggregation</strong>
<p>Column aggregation looked great initially &#8211; I could have a &#8220;TypeAEntry&#8221; and a &#8220;TypeBEntry&#8221;, and Doctrine would have handled the typing of the Entry automatically.  I couldn&#8217;t however see a way to query &#8220;in reverse&#8221; &#8211; get all Entries and their associated models.</li>
<li> <strong>Write a raw SQL query, and use Doctrine&#8217;s PDO instance to retrieve the data.</strong></li>
</ol>
<p>Option 3) was the one I settled for in the end.  It meant of course that I had to specify column names, and perform all the joins myself, but it did mean I could specify precisely what data I wanted back.  This came back in the form of a normal array.  I&#8217;d tried to stay away from this option intially, but after spending too long researching the other 2 and hitting brick walls, I bit the bullet and dropped down to the raw stuff.  And hey presto!</p>
<p>Note &#8211; this approach will only work if you want the data to be read-only.  If you want to then use Doctrine&#8217;s model goodness, you&#8217;ll need to work out how to transform that *back* into a model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2009/10/16/dont-be-afraid-to-not-use-the-or/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Why I hate Criteria&#8221;</title>
		<link>http://www.whiteoctober.co.uk/blog/2008/10/08/why-i-hate-criteria/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2008/10/08/why-i-hate-criteria/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 12:46:06 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[Object-relational mapping]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/?p=153</guid>
		<description><![CDATA[Nicking the title from the previous post, oh and the sentiment. I don&#8217;t hate Criteria**, it is actually quite good, however watching the video in the previous post reminded me of a few issues we have had in the office where we have complained about it or just got plain confused&#8230; I know Dan, for [...]]]></description>
			<content:encoded><![CDATA[<p>Nicking the title from the <a href="http://www.whiteoctober.co.uk/blog/2008/10/07/why-i-hate-django/">previous post</a>, oh and the sentiment.  I don&#8217;t hate <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/Criteria">Criteria</a>**, it is actually quite good, however watching the video in the previous post reminded me of a few issues we have had in the office where we have complained about it or just got plain confused&#8230;</p>
<p>I know <a href="http://www.whiteoctober.co.uk/meet-the-staff-_27.html#dan">Dan</a>, for example, doesn&#8217;t see the point of using Criteria because what is wrong with SQL?</p>
<p>I have sat and scratched my head a few times trying to figure out how to query using Criteria, I know how I would do it in SQL but I can sit for ages trying to bend Criteria to my will.</p>
<p>I really should have <a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/Criteria">RTFM</a>&#8230;</p>
<p style="padding-left: 30px;"><em>We do still recommend that you use SQL when it proves to be simpler, though.</em></p>
<p>Criteria is great when it fits your needs, but when it doesn&#8217;t or becomes very complex..stop step back and use SQL.</p>
<p>Using <a href="http://propel.phpdb.org/trac/">Propel 1.3</a> you get to use <a href="http://uk.php.net/manual/en/intro.pdo.php">PDO</a> and that is not something that is framework specific it&#8217;s an inbuilt <a href="http://www.php.net">PHP</a> database abstraction layer. So the skills you learn using PDO are transferable to another project that doesn&#8217;t use a framework but uses a database.</p>
<p>So we have a custom query that we want to run and get back a bunch of user objects and we really don&#8217;t want to use Criteria&#8230;easy:</p>
<p style="padding-left: 30px;">$name = &#8220;Wards&#8221;;<em><br />
</em>$bunchofusers = array();<em><br />
//Our highly complex query&#8230;.<br />
//Fancy prepared stuff you get from PDO&#8230;think sprintf<br />
</em>$stmt = $con-&gt;prepare(&#8220;SELECT * FROM user WHERE last_name = ?&#8221;);<br />
$stmt-&gt;bindValue(1, $name);<em><br />
//erm execute&#8230;<br />
</em>$stmt-&gt;execute();<em><br />
//Loop on our rows&#8230;and lets make some User objects..<br />
</em>while($row = $stmt-&gt;fetch()) {<br />
$oUser = new User();<br />
$oUser-&gt;hydrate($row);<br />
$bunchofusers[]=$oUser;<br />
}</p>
<p>Nothing really new to learn in the above code, it&#8217;s more like remembering that we can code how we choose too and we don&#8217;t have to be shackled to a certain way or slowed down by a framework when things don&#8217;t exactly fit.</p>
<p>** <em>&#8220;What is Criteria?&#8221; I hear you say&#8230;well it comes with the Propel ORM, and it is for building up queries using objects rather than SQL. We use Propel within the <a href="http://www.symfony-project.org/">symfony framework</a> as our current ORM of choice.</em></p>
<div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Zemified by Zemanta" href="http://reblog.zemanta.com/zemified/a771d9f4-e213-47b4-b5f8-cafd6ee09603/"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=a771d9f4-e213-47b4-b5f8-cafd6ee09603" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2008/10/08/why-i-hate-criteria/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dear Idiot Boy,</title>
		<link>http://www.whiteoctober.co.uk/blog/2008/03/14/dear-idiot-boy/</link>
		<comments>http://www.whiteoctober.co.uk/blog/2008/03/14/dear-idiot-boy/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 08:06:15 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[bbc]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[drm]]></category>
		<category><![CDATA[iplayer]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.whiteoctober.co.uk/blog/2008/03/14/dear-idiot-boy/</guid>
		<description><![CDATA[Do you think even I would use Javascript to secure content?! Idiot boy. It was simple to secure and NO ONE will ever know how I have done it. MWHAHAHA Auntie. &#8212;&#8212;&#8212;&#8212;- Erm well I&#8217;m a bit stunned. I thought it would be something at least &#8220;clever&#8221; with cookies and javascript that was &#8220;the fix&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Do you think even I would use Javascript to secure content?! Idiot boy.</p>
<p>It was simple to secure and NO ONE will ever know how I have done it.</p>
<p>MWHAHAHA</p>
<p>Auntie.<br />
&#8212;&#8212;&#8212;&#8212;-</p>
<p>Erm well I&#8217;m a bit stunned. <a href="http://po-ru.com/diary/bbc-iplayer-fix-hacked-again/">I thought</a> it would be something at least &#8220;clever&#8221; with cookies and javascript that was &#8220;<a href="http://news.bbc.co.uk/1/hi/technology/7293988.stm">the fix</a>&#8221; that &#8220;secured&#8221; the iPhone version of the iPlayer. But no. All they are doing is checking the the user agent string again!</p>
<p>This time for the QuickTime user agent:  &#8220;Apple iPhone v1.1.3 CoreMedia v1.0.0.4A93&#8243;</p>
<p>It does mean however that you can&#8217;t just use a browser based switcher but as I predicted someone had figured it out by the end of the day. <a href="http://po-ru.com/diary/bbc-iplayer-fix-hacked-again/">10 minutes to midnight</a>.</p>
<p>Now I can&#8217;t seem to get Ruby working on my box but I may quickly knock up a PHP/libCurl version of this as its so simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.whiteoctober.co.uk/blog/2008/03/14/dear-idiot-boy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

