<?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>Christopher Shennan&#039;s Blog &#187; Symfony</title>
	<atom:link href="http://www.chrisshennan.com/category/php/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisshennan.com</link>
	<description>A day in the life of...</description>
	<lastBuildDate>Thu, 15 Sep 2011 15:13:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Doctrine Inflector &#8211; Method names for address_1</title>
		<link>http://www.chrisshennan.com/2011/02/02/doctrine-inflector-method-names-for-address_1/</link>
		<comments>http://www.chrisshennan.com/2011/02/02/doctrine-inflector-method-names-for-address_1/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 18:54:31 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[Diem Project]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[doctrine inflector]]></category>
		<category><![CDATA[method names]]></category>
		<category><![CDATA[method names in php]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=545</guid>
		<description><![CDATA[You have probably come across this already but I have tripped up over this problem a few times. If you have fields in the db like address_1, address_2, address_3 then the _ is not removed when using getter/setter methods i.e. I have been trying to use:- echo $object-&#62;getAddress1&#40;&#41; echo $object-&#62;getAddress2&#40;&#41; and it needs to be:- [...]]]></description>
			<content:encoded><![CDATA[<p>You have probably come across this already but I have tripped up over this problem a few times.</p>
<p>If you have fields in the db like address_1, address_2, address_3 then the _ is not removed when using getter/setter methods</p>
<p><span id="more-545"></span><br />
i.e. I have been trying to use:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAddress1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAddress2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>and it needs to be:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAddress_1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAddress_2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>I am assuming the Doctrine Inflector is not removing the _ because the character immediately after it is a number rather than a letter, along the same principles as class names can not start with a number (<a href="http://php.net/manual/en/language.oop5.basic.php" target="_blank">PHP 5 &#8211; The Basics</a>).</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2011/02/02/doctrine-inflector-method-names-for-address_1/' addthis:title='Doctrine Inflector &#8211; Method names for address_1 ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2011/02/02/doctrine-inflector-method-names-for-address_1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ORM Designer &#8211; A visual editor for PHP Doctrine, Doctrine2, Propel and CakePHP</title>
		<link>http://www.chrisshennan.com/2010/09/20/orm-designer-a-visual-editor-for-php-doctrine-doctrine2-propel-and-cakephp/</link>
		<comments>http://www.chrisshennan.com/2010/09/20/orm-designer-a-visual-editor-for-php-doctrine-doctrine2-propel-and-cakephp/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 20:40:19 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[mysql workbench]]></category>
		<category><![CDATA[orm designer]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=359</guid>
		<description><![CDATA[A week or so I got an unexpected email from Ludek Vodicka asking me to have a look at ORM Designer for creating and maintaining my database schemas for the Symfony projects I have been working on.  Up until now I have been using MySQL Workbench to create my ER-diagrams and maintain my database structure [...]]]></description>
			<content:encoded><![CDATA[<p>A week or so I got an unexpected email from Ludek Vodicka asking me to have a look at <a href="http://www.orm-designer.com/" target="_blank">ORM Designer</a> for creating and maintaining my database schemas for the Symfony projects I have been working on.  Up until now I have been using MySQL Workbench to create my ER-diagrams and maintain my database structure but I&#8217;ve come up against a few obstacles when trying to use it with projects using doctrine so I thought why now.</p>
<p>I fully expected <a href="http://www.orm-designer.com/" target="_blank">ORM Designer</a> to be a MySQL Workbench clone (and it&#8217;s obviously been a question that has been raised before &#8211; <a href="http://www.orm-designer.com/article/orm-designer-and-mysql-workbench-comparison" target="_blank">ORM Designer and MySQL Workbench comparison</a>) but I must admit I was pleasantly surprised to find out is was not.  To try and break myself into it easily I opted to start working on the database schema for the re-build of <a href="http://www.managemyalerts.com" target="_blank">Manage My Alerts</a> which I have intended to re-build using Symfony for quite a while.<br />
<span id="more-359"></span></p>
<p>I was a little concerned as the re-build is using <a href="http://www.apostrophenow.com" target="_blank">Apostrophe Now!</a> and I was unsure how <a href="http://www.orm-designer.com/" target="_blank">ORM Designer</a> would interact with everything.  My first pleasant surprise was when I first opened <a href="http://www.orm-designer.com/" target="_blank">ORM Designer</a> and was presented with an option to &#8220;Import from ORM&#8221;.  This was ideal as <a href="http://www.apostrophenow.com" target="_blank">Apostrophe Now!</a> already have their own schema in place I obviously want to link my entities to the relevant user accounts using the pre-installed sfDoctrineGuardUser so I need to be able to interact with these entities even though they&#8217;re not being added by myself.</p>
<p>My second pleasant surprise was that when the schema files were imported they were sorted out into their relevant &#8220;regions&#8221; (or in my case plugins) so you could quickly see at a glance what belongs to what (sfGuardUser, sfGuardGroup etc all part of sfDoctrineGuardPlugin) and you also have a blank region set up for adding your own schema for your project.  With all that taken care for you, you can quickly jump in and start working, unlike with <a href="http://wb.mysql.com/" target="_blank">MySQL Workbench</a> in which you have to shuffle everything around and sort it out into a logical order yourself before you can do anything.</p>
<p>It took me a little while to figure out everything I needed (Entities, setting onDelete actions, creating relations and getting them the right way round) but everything seems to be there and adding behaviours has been reduced to a point and click which is fantastic as I don&#8217;t have try and remember what they are called anymore!</p>
<p>The only con I can find with <a href="http://www.orm-designer.com/" target="_blank">ORM Designer</a> is that it had a €99 price tag attached and I&#8217;ve always been one for going for the free alternatives so normally <a href="http://wb.mysql.com/" target="_blank">MySQL Workbench</a> would win over, however, in this case I am finding the benefits outweigh the cost and I am seriously considering switching when the trial period is up.</p>
<h2>References</h2>
<p><a href="http://www.orm-designer.com/" target="_blank">ORM Designer</a> &#8211; Visual editor for PHP Doctrine, Doctrine2, Propel and CakePHP</p>
<p><a href="http://wb.mysql.com/" target="_blank">MySQL Workbench</a> &#8211; A cross-platform, visual database design tool developed by MySQL.</p>
<p><a href="http://www.apostrophenow.com/" target="_blank">Apostrophe Now!</a> &#8211; A content management system designed for maximum flexibility with a minimal learning curve.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/09/20/orm-designer-a-visual-editor-for-php-doctrine-doctrine2-propel-and-cakephp/' addthis:title='ORM Designer &#8211; A visual editor for PHP Doctrine, Doctrine2, Propel and CakePHP ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2010/09/20/orm-designer-a-visual-editor-for-php-doctrine-doctrine2-propel-and-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Method Signatures &#8211; Pass values as individual parameters or an option array?</title>
		<link>http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/</link>
		<comments>http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 11:07:47 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[method signatures]]></category>
		<category><![CDATA[options array]]></category>
		<category><![CDATA[parameter passing]]></category>
		<category><![CDATA[parameters vs option array]]></category>
		<category><![CDATA[parameters vs options]]></category>
		<category><![CDATA[symfony options array]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=330</guid>
		<description><![CDATA[Over the last few months I have been working with Symfony and have got used to passing values to methods via an options array but I have recently had to pick up an older project in which the values are passed to the methods by individual parameters. This has given me a good opportunity to [...]]]></description>
			<content:encoded><![CDATA[<h4><span style="font-weight: normal;">Over the last few months I have been working with Symfony and have got used to passing values to methods via an options array but I have recently had to pick up an older project in which the values are passed to the methods by individual parameters. </span></h4>
<h4><span style="font-weight: normal;">This has given me a good opportunity to evaluate both techniques and determine my personal preference for working.</span></h4>
<p>The more traditional technique is to pass values to methods using individual parameters as in the example below:-</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> someMethod<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$age</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: #666666; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The benefit I have found with this method is that you can clearly identify what needs to be passed to the method, however, if you need to change the method to include an additional parameter it means that you have to update every call to this method so that every parameter is specified.<br />
<span id="more-330"></span><br />
An alternative (and my personal preference) is to used an option array like in the following example</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> someMethod<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</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: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$defaults</span> <span style="color: #339933;">=</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;">'chris'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'age'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$defaults</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case, if you need to add an extra parameter to the method you can simply add the value to the options array and update the functionality within the method.  You do not necessarily need to update the calls to this method that are already in place  because they should still work fine provided the updated functionality is defined in such a way that it allows for the new parameter to be optional.</p>
<p>In addition, I feel that if you provide decent documentation regarding the options array (which should include a list of all the options values allowed), especially if it can be picked up via auto-completion in IDEs such as <a href="http://www.netbeans.com/" target="_blank">Netbeans</a>, then this is just as easy to use as methods which are defined to accept individual parameters.</p>
<h4>References</h4>
<p><a href="http://weblogtoolscollection.com/archives/2010/02/25/passing-parameters-as-variables-vs-passing-parameters-as-an-array/" target="_blank">http://weblogtoolscollection.com/archives/2010/02/25/passing-parameters-as-variables-vs-passing-parameters-as-an-array/</a></p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/' addthis:title='Method Signatures &#8211; Pass values as individual parameters or an option array? ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Raw SQL from Doctrine Query Object &#8211; Revised</title>
		<link>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/</link>
		<comments>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 19:47:21 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctine]]></category>
		<category><![CDATA[doctrine query object]]></category>
		<category><![CDATA[raw sql]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=232</guid>
		<description><![CDATA[A few months ago I posted an article taking about how to get the raw SQL from a Doctrine Query Object but with the release of Symfony 1.3 and Symfony 1.4 it would appear that the code no longer works.  As a result I&#8217;ve updated the code to work with Symfony 1.2 &#8211; 1.4 and [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I posted an article taking about how to get the <a href="/2009/09/22/raw-sql-from-a-doctrine-query-object/" target="_self">raw SQL from a Doctrine Query Object</a> but with the release of <a href="http://www.symfony-project.org/installation/1_3" target="_blank">Symfony 1.3</a> and <a href="http://www.symfony-project.org/installation/1_4" target="_blank">Symfony 1.4</a> it would appear that the code no longer works.  As a result I&#8217;ve updated the code to work with Symfony 1.2 &#8211; 1.4 and you can find the updated source below:-<br />
<span id="more-232"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_raw_sql<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</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: #009900;">&#40;</span><span style="color: #000088;">$query</span> instanceof Doctrine_Query<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> sfException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Not an instanse of a Doctrine Query'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</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: #990000;">is_callable</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'buildSqlQuery'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildSqlQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$query_params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query_params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'where'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSql</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$queryStringParts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$iQC</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$param</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_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</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: #990000;">is_bool</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$iQC</span><span style="color: #339933;">++;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope that it proves useful.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/' addthis:title='Raw SQL from Doctrine Query Object &#8211; Revised ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>TRUNCATE TABLE with Symfony and Doctrine</title>
		<link>http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/</link>
		<comments>http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 20:59:25 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine truncate table]]></category>
		<category><![CDATA[mysql truncate table]]></category>
		<category><![CDATA[symfony import routines]]></category>
		<category><![CDATA[symfony truncate table]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=178</guid>
		<description><![CDATA[I am often importing data into a symfony project from an existing site or a CSV file and re-writing this data into the fixtures.yml is usually too complicated or time consuming so I end up writing bespoke import actions. While I am writing these actions I often find that I have to delete the contents [...]]]></description>
			<content:encoded><![CDATA[<p>I am often importing data into a symfony project from an existing site or a CSV file and re-writing this data into the fixtures.yml is usually too complicated or time consuming so I end up writing bespoke import actions.</p>
<p>While I am writing these actions I often find that I have to delete the contents of the MySQL tables as you can never write the routine complete and accurate in one go so as you build it up in smaller steps you find that you have to get rid of the previously old data.</p>
<p>This presented me with 2 problems:-</p>
<ul>
<li>Using DELETE FROM [TABLENAME] does not reset the auto-incrementing fields so if you have anything that is based on the id during the rest of the import then you&#8217;re going to have issues.</li>
<li>There is a lot of clicking in phpMyAdmin to empty the tables, especially if you forget about the foreign key relationships.</li>
</ul>
<p><span id="more-178"></span></p>
<p>I found that MySQL had a TRUNCATE TABLE but this is not directly available via Doctrine as the TRUNCATE TABLE is function of the type of database you are using and Doctrine cannot assume you are always using MySQL so therefore it cannot provide a generic method to call it.</p>
<p>Having said that it was not too difficult to run the TRUNCATE TABLE from within my Symfony project.  All I had to do was add the following lines of code to an action within the actions.class.php for my import module and now it empties each table I have defined before importing the data and it also resets the auto-incrememt ids all my tables start from id = 1 each time I run the import.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dbh</span> <span style="color: #339933;">=</span> Doctrine_Manager<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCurrentConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #000088;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TRUNCATE TABLE order_items'</span><span style="color: #009900;">&#41;</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: #0000ff;">'TRUNCATE TABLE orders'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dbh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Be careful which order you run the TRUNCATE TABLE calls so you avoid the foreign key relationship issues.</p>
<p>Let me know if this helps you out.  Enjoy!</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/' addthis:title='TRUNCATE TABLE with Symfony and Doctrine ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Raw SQL from a Doctrine Query Object</title>
		<link>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/</link>
		<comments>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 19:01:49 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=138</guid>
		<description><![CDATA[This has been updated to work with Symfony 1.3/1.4 &#8211; Please go to the updated article: Raw SQL from Doctrine Query Object – Revised As my use of Symfony is increasing I find myself frustrated that there doesn&#8217;t appear to be an easy way to get the raw SQL from a doctrine query object so [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This has been updated to work with Symfony 1.3/1.4 &#8211; Please go to the updated article:  <a href="/2009/12/07/raw-sql-from-doctrine-query-object-revised/">Raw SQL from Doctrine Query Object – Revised</a></strong></p>
<p>As my use of Symfony is increasing I find myself frustrated that there doesn&#8217;t appear to be an easy way to get the raw SQL from a doctrine query object so I can simply output it and paste it into phpMyAdmin to debug problems with the SQL.  I may be wrong about this but as yet I have not found a built in function to perform this operation.</p>
<p>Sure I am able to output the query with the &#8220;?&#8221; indicating where the necessary values are to go and I can also easily output the array of query parameters so I can substitute these manually but this takes time and it would be much much simpler and quicker to just output the whole query with the substitution already done so it&#8217;s a simply copy and paste of the raw SQL from the doctrine query object straight into phpMyAdmin.</p>
<p>I have wrote a quick function to do this and I had meant to post this for a while but I just have not had the chance to get round to it until now.<br />
<span id="more-138"></span><br />
The code for this is can be found below:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_raw_sql<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$queryStringParts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSQL</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;">$iQC</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$param</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_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</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: #990000;">is_bool</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$iQC</span><span style="color: #339933;">++;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In my case this is a global function but it could very well be written as a static function in a debug class.</p>
<p>$query is a Doctrine Query object and this function iterates round the parameters for the query string and replaces each instance of a &#8220;?&#8221; with the corresponding variable.  It has a crude (but fairly effective so far) method of determine whether it&#8217;s a string, number or boolean when performing this substitution and so far this works well in all the cases I&#8217;ve used it.</p>
<p>The $query->limit(0); is very important as the $query->getSQL() function does not work properly in this context if a limit is specified on the query so as we are wanting to debug the SQL and a majority of the time we are not concerned with the limit I have opted to remove this from this routine.</p>
<p>Hopefully this will allow you to save some time and effort trying to get the raw SQL from your doctrine query objects and I would appreciated any comments, thoughts or ideas you may have for improvement.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/' addthis:title='Raw SQL from a Doctrine Query Object ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why you should answer your own posts?</title>
		<link>http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/</link>
		<comments>http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 20:18:15 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=127</guid>
		<description><![CDATA[How many times have you searched for the answer to a problem in Google to find nothing but forums with people who have the same questions but no solutions posted even though the question was raised months, even years earlier? If you post a question and no-one managed to provide you with an answer do [...]]]></description>
			<content:encoded><![CDATA[<p>How many times have you searched for the answer to a problem in Google to find nothing but forums with people who have the same questions but no solutions posted even though the question was raised months, even years earlier?  </p>
<p>If you post a question and no-one managed to provide you with an answer do you:-</p>
<ul>
<li>post up your solution when you&#8217;ve found it? or</li>
<li>simply forget about the post and leave everyone else to figure it out themselves too?</li>
</ul>
<p>Unfortunately there are a number of people in the latter category (myself included from time to time) and being a web developer means I run into this type of issue more than I would like but, I&#8217;ve recently come across yet another great reason why you should go back and answer your own question when you have managed to work out the answer.<br />
<span id="more-127"></span><br />
A few months ago I was working for <a href="http://www.alienationdigital.co.uk" target="_blank">Alienation Digital</a> in Glasgow and I had a problem with creating a <a href="http://forum.symfony-project.org/index.php/mv/tree/20144/76457/" target="_blank">custom validator using a callback in Symfony</a> and I posted the problem to the Symfony forums, and later, the solution I used to rectify the problem.</p>
<p>Fast forward a few months and you now find me working for <a href="http://www.line.uk.com" target="_blank">Line Digital</a> in Edinburgh and I&#8217;m now working on a new project which has a very similar problem.  Obviously I don&#8217;t have access to the code I wrote while at <a href="http://www.alienationdigital.co.uk" target="_blank">Alienation Digital</a> but unsurprisingly I had forgotten I have already solved this problem as it&#8217;s months since I had to last think about it.</p>
<p>So out comes Google again, I enter my search phrase and I am amazed that the first forum post (which resulted in the path to the solution) was my own post that I wrote while at <a href="http://www.alienationdigital.co.uk" target="_blank">Alienation Digital</a>.</p>
<p>So the moral of the story is to answer your own posts, even if you do end up feeling like you&#8217;re talking to yourself because you the next person your post helps out may be yourself.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/' addthis:title='Why you should answer your own posts? ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony &#8211; Does not have a registered handler</title>
		<link>http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/</link>
		<comments>http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 16:57:01 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[line digital]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=98</guid>
		<description><![CDATA[Last week I was working away in the office at Line Digital on our latest Symfony based project when our project started giving us a strange error similar to:- Fatal error: Uncaught exception &#8216;sfConfigurationException&#8217; with message &#8216;Configuration file &#38;quot;/usr/lib/php/symfony/config/config/core_compile.yml&#38;quot; does not have a registered handler.&#8217; in /usr/lib/php/symfony/config/sfConfigCache.class.php:101 Looking into this a little closer we found [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I was working away in the office at <a title="Line Digital" href="http://www.line.uk.com" target="_blank">Line Digital</a> on our latest Symfony based project when our project started giving us a strange error similar to:-</p>
<blockquote><p>Fatal error:  Uncaught exception &#8216;sfConfigurationException&#8217; with message &#8216;Configuration file &amp;quot;/usr/lib/php/symfony/config/config/core_compile.yml&amp;quot; does not have a registered handler.&#8217; in /usr/lib/php/symfony/config/sfConfigCache.class.php:101</p></blockquote>
<p>Looking into this a little closer we found that the server had ran out of disk space so after making some space and using &#8220;symfony cc&#8221; to clear the cache we thought that this would have resolved the problem, however we continued to get the &#8220;does not have a registered handler&#8221; message being presented.</p>
<p><span id="more-98"></span>In the end, we had to clear the cache manually with a command similar to:-</p>
<blockquote><p>rm -fr cache/*</p></blockquote>
<p>For some reason this seemed to work fine where as the &#8220;symfony cc&#8221; command didn&#8217;t work therefore the only conclusion that we could come up with is that when the server ran out of disk space it corrupted something in the symfony cache which either is not normally cleared with a &#8220;symfony cc&#8221; and as a result we needed to remove it completely so symfony could re-build it automatically.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/' addthis:title='Symfony &#8211; Does not have a registered handler ' ><a href="//addthis.com/bookmark.php?v=250&amp;username=xa-4d2b47597ad291fb" class="addthis_button_compact">Share</a><span class="addthis_separator">|</span><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

