<?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; PHP</title>
	<atom:link href="http://www.chrisshennan.com/category/php/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>Backticks, Apostrophes and Quotation Marks</title>
		<link>http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/</link>
		<comments>http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 20:47:55 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[apostrophes]]></category>
		<category><![CDATA[backticks]]></category>
		<category><![CDATA[backtics]]></category>
		<category><![CDATA[quotation marks]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=462</guid>
		<description><![CDATA[I was trying to assist someone with the difference between backtics, apostrophes and quotation marks. The three are used in different circumstances and the the basic rules I use with &#8216;, ` and &#34; are:- I only use ` in MySQL and only where the field or table name is a reserved word i.e. you [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to assist someone with the difference between backtics, apostrophes and quotation marks.  The three are used in different circumstances and the the basic rules I use with &#8216;, ` and &quot; are:-</p>
<p>I only use ` in MySQL and only where the field or table name is a reserved word i.e. you have a field called date so the query ends up like</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> title<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`date`</span> <span style="color: #993333; font-weight: bold;">FROM</span> sometable</pre></div></div>

<p><span id="more-462"></span><br />
I use &#8216; and &quot; within PHP for different things:</p>
<p>if we have a variable called $test with a value of &#8220;this is my sample data&#8221;;</p>
<p>&#8216; spits out exactly what&#8217;s within the apostrophes (variable aren&#8217;t evaluated) so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'My text is: $test'</span><span style="color: #339933;">;</span></pre></div></div>

<p>will output</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">My text is: $test</pre></div></div>

<p>&quot; allows the variables to be evaluated so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;My text is: <span style="color: #006699; font-weight: bold;">$test</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>will output</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">My text is: this is my sample data</pre></div></div>

<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/12/08/backticks-apostrophes-and-quotation-marks/' addthis:title='Backticks, Apostrophes and Quotation Marks ' ><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/12/08/backticks-apostrophes-and-quotation-marks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DmMedia &#8211; SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry</title>
		<link>http://www.chrisshennan.com/2010/11/25/dmmedia-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry/</link>
		<comments>http://www.chrisshennan.com/2010/11/25/dmmedia-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 20:39:38 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[Diem Project]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[diem]]></category>
		<category><![CDATA[diem media]]></category>
		<category><![CDATA[diem media manager]]></category>
		<category><![CDATA[DmMedia]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=450</guid>
		<description><![CDATA[Today a client was reporting issues with uploading an image via the media section of the diem project administration pages. The error was:- SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#8216;Logo.JPG&#8217; for key 2 I recall having issues with this whilst developing a previous diem based site and the issue turned out to be something [...]]]></description>
			<content:encoded><![CDATA[<p>Today a client was reporting issues with uploading an image via the media section of the <a href="http://www.diem-project.org" target="_blank">diem project</a> administration pages.  The error was:-</p>
<blockquote><p>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#8216;Logo.JPG&#8217; for key 2</p></blockquote>
<p>I recall having issues with this whilst developing a previous diem based site and the issue turned out to be something rather simple.<br />
<span id="more-450"></span><br />
What had happened was the user had previously uploaded an image called Logo.jpg and had now uploaded an image called Logo.JPG (note the difference in case of the file extension).  Although the file system allows this, diem can not handle duplicate filenames which differ only in case.</p>
<p>To resolve this I deleted both images and told the client to ensure all filename, including file extensions were all in lower case and this should not arise again.  You could delete one and leave the other in place but I thought it best to get the client to re-upload the image in order to avoid any confusion.</p>
<p>Hopefully this will help save others time in trying to debug this SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry issue.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/11/25/dmmedia-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry/' addthis:title='DmMedia &#8211; SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ' ><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/11/25/dmmedia-sqlstate23000-integrity-constraint-violation-1062-duplicate-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wpTwit and lineTwit now available!</title>
		<link>http://www.chrisshennan.com/2010/10/26/wptwit-and-linetwit-now-available/</link>
		<comments>http://www.chrisshennan.com/2010/10/26/wptwit-and-linetwit-now-available/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 19:19:29 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[line digital]]></category>
		<category><![CDATA[lineTwit]]></category>
		<category><![CDATA[myTwit]]></category>
		<category><![CDATA[php twitter reader]]></category>
		<category><![CDATA[Ralph Slooten]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[wpTwit]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=442</guid>
		<description><![CDATA[I have been working on these 2 projects on and off for a couple of weeks and although it has taken me much longer to package up and write the documentation for these 2 projects, I have finally managed to get them finished to a reasonable state and both projects are available for download. lineTwit [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on these 2 projects on and off for a couple of weeks and although it has taken me much longer to package up and write the documentation for these 2 projects, I have finally managed to get them finished to a reasonable state and both projects are available for download.</p>
<p><a href="/my-projects/linetwit-a-php-twitter-reader-based-on-mytwit/">lineTwit </a>- A PHP Twitter Reader &#8211; Original developed at my work (<a href="http://www.line.uk.com" target="_blank">Line Digital</a>) and is based on <a href="http://www.axllent.org/projects/mytwit" target="_blank">myTwit </a>by <a href="http://www.axllent.org/about_me" target="_blank">Ralph Slooten</a></p>
<p><a href="/my-projects/wptwit-a-php-twitter-reader-for-wordpress/">wpTwit </a>-  A WordPress Plugin build using <a href="/my-projects/linetwit-a-php-twitter-reader-based-on-mytwit/">lineTwit</a> to show how it can be incorporated into proper projects.  This site is live example of this plugin in action as I am using wpTwit for the twitter feed in the sidebar.</p>
<p>Many thanks to both <a href="http://www.line.uk.com" target="_blank">Line Digital</a> and <a href="http://www.axllent.org/about_me" target="_blank">Ralph Slooten</a> for allowing me to make these available for everyone to use.</p>
<p>Enjoy!</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/10/26/wptwit-and-linetwit-now-available/' addthis:title='wpTwit and lineTwit now available! ' ><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/10/26/wptwit-and-linetwit-now-available/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>WordPress wp_redirect() shows a blank page</title>
		<link>http://www.chrisshennan.com/2010/02/27/wordpress-wp_redirect-shows-a-blank-page/</link>
		<comments>http://www.chrisshennan.com/2010/02/27/wordpress-wp_redirect-shows-a-blank-page/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 21:04:31 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[output_buffering]]></category>
		<category><![CDATA[php_flag]]></category>
		<category><![CDATA[redirection]]></category>
		<category><![CDATA[wordpress plugin]]></category>
		<category><![CDATA[wp_redirect]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=278</guid>
		<description><![CDATA[Over the last few weeks I have been working on my first wordpress plugin and I am quickly getting to grips with how it all pieces together but I ran into a problem with a rather basic piece of functionality that pretty much rendered the plugin useless until I figured out the issue. The section [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few weeks I have been working on my first wordpress plugin and I am quickly getting to grips with how it all pieces together but I ran into a problem with a rather basic piece of functionality that pretty much rendered the plugin useless until I figured out the issue.</p>
<p>The section I was working on was a form submission (within the wordpress administation) which saved the form values into the database and then redirected the user upon success to another page (using wp_redirect) but this resulted in a blank content pane.</p>
<p>This seems very strange to me as it showed some of the page contents i.e. the header and left navigation but the content pane was completely blank.<br />
<span id="more-278"></span></p>
<p>I searched around for a few hours trying various suggestions to similar problems, downloading other wordpress plugins and examining how they used the wp_redirect function to see if the authors of these other wordpress plugins had done anything different, only to find that there was no difference.</p>
<p>I eventually managed to figure out the issue after I read a post regarding a problem another user was having where they were getting a completely blank screen and another member suggested the problem could be due to whitespace which was sent to the browser before the redirect was called resulting in a &#8220;headers already sent&#8221; problem.</p>
<p>This got me thinking that I did not have output buffering enabled which was strange as I usually have output buffering enabled to resolve this issue, however, in this case I did not have output buffering turned on and this turned out to be exactly the problem.  I added the following line to my .htaccess file and the redirection now works perfectly.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">php_flag output_buffering on</pre></div></div>

<p>I was glad to get this one resolved as I had to spend far too much time on something that I have resolved time and time again.  Certainly one I&#8217;ll be aware of should there be a next time!</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2010/02/27/wordpress-wp_redirect-shows-a-blank-page/' addthis:title='WordPress wp_redirect() shows a blank page ' ><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/02/27/wordpress-wp_redirect-shows-a-blank-page/feed/</wfw:commentRss>
		<slash:comments>12</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>csNews Pro</title>
		<link>http://www.chrisshennan.com/2009/11/22/csnews-pro/</link>
		<comments>http://www.chrisshennan.com/2009/11/22/csnews-pro/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 19:01:32 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cNews pro]]></category>
		<category><![CDATA[design2host]]></category>
		<category><![CDATA[v-desk]]></category>
		<category><![CDATA[v-desk newsletter system]]></category>
		<category><![CDATA[v-desk.com]]></category>
		<category><![CDATA[vdesk]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=225</guid>
		<description><![CDATA[It&#8217;s taken me a while but I&#8217;ve finally managed to create the &#8220;My Projects&#8221; section started although in all likelyhood I&#8217;ll not have much time to devote to my projects. I&#8217;ve started off by resurrection an old project that I worked on while I was self employed as Design2Host Ltd.  csNews Pro (formerly V-Desk Newsletter [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s taken me a while but I&#8217;ve finally managed to create the &#8220;<a href="/my-projects/">My Projects</a>&#8221; section started although in all likelyhood I&#8217;ll not have much time to devote to my projects.</p>
<p>I&#8217;ve started off by resurrection an old project that I worked on while I was self employed as Design2Host Ltd.  <a href="/my-projects/csnews-pro-formerly-v-desk-newsletter-system-pro/">csNews Pro (formerly V-Desk Newsletter System Pro)</a> has had a few cosmetic details changed (changed the name, removed the licence key limitions) but it&#8217;s exactly the same project and it is compatible with the paid version that was original available so you can easily convert from the previous paid version across to the free version when any updates become available.</p>
<p>Feel free to download and play with <a href="/my-projects/csnews-pro-formerly-v-desk-newsletter-system-pro/">csNews Pro</a> and feel free to give my any feedback on it.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://www.chrisshennan.com/2009/11/22/csnews-pro/' addthis:title='csNews Pro ' ><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/22/csnews-pro/feed/</wfw:commentRss>
		<slash:comments>0</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>
	</channel>
</rss>

