<?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>ramblings &#187; php</title>
	<atom:link href="http://techore.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://techore.com</link>
	<description>come to your own conclusions</description>
	<lastBuildDate>Mon, 30 Aug 2010 15:08:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>quickie: creating symfony delete button</title>
		<link>http://techore.com/2010/01/quickie-creating-symfony-delete-button/</link>
		<comments>http://techore.com/2010/01/quickie-creating-symfony-delete-button/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 17:59:47 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[delete button]]></category>
		<category><![CDATA[delete link]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[quickie]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[symfony 1.2]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=246</guid>
		<description><![CDATA[Many months ago I had asked for help on the symfony forums on how to create a delete button using either the link_to() or button_to() method. I had tried but was always getting validation errors. Today a person asked whether anyone had figured out a solution. It prompted me to do more research into symfony's core code and found a solution (though the solution wasn't in the core code).

Original delete text link code:

echo link_to('Delete', 'state/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?'));
New delete BUTTON link code:

echo link_to('Delete', 'state/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?'));
Till Next Time]]></description>
			<content:encoded><![CDATA[<p>Many months ago I had asked for help on the symfony forums on how to create a delete button using either the link_to() or button_to() method.  I had tried but was always getting validation errors.  Today a person asked whether anyone had figured out a solution.  It prompted me to do more research into symfony&#8217;s core code and found a solution (though the solution wasn&#8217;t in the core code).</p>
<p>Original delete text link code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> link_to<span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'Delete'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'state/delete?id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'confirm'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Are you sure?'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>New delete BUTTON link code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> link_to<span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'&lt;button&gt;Delete&lt;/button&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'state/delete?id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'confirm'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Are you sure?'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2010/01/quickie-creating-symfony-delete-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>quickie: setting symfony datetime default</title>
		<link>http://techore.com/2010/01/quickie-setting-symfony-datetime-default/</link>
		<comments>http://techore.com/2010/01/quickie-setting-symfony-datetime-default/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 20:23:23 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[form fields]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[quickie]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=243</guid>
		<description><![CDATA[Setting the default value for a symfony form field is one of those tasks so simple that it's impossible to find out how to do it without a good bit of trial and error.  So without further ado, here is how to set a DateTime field's default value:
$this->widgetSchema['start_time']->setDefault(date("m/d/Y", now()));]]></description>
			<content:encoded><![CDATA[<p>Setting the default value for a symfony form field is one of those tasks so simple that it&#8217;s impossible to find out how to do it without a good bit of trial and error.  So without further ado, here is how to set a DateTime field&#8217;s default value:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'start_time'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDefault</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;m/d/Y&quot;</span><span style="color: #339933;">,</span> now<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2010/01/quickie-setting-symfony-datetime-default/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>updating symfony form values after submitting</title>
		<link>http://techore.com/2010/01/updating-symfony-form-values-after-submitting/</link>
		<comments>http://techore.com/2010/01/updating-symfony-form-values-after-submitting/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 21:46:36 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[form update]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sfForms]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=240</guid>
		<description><![CDATA[One thing that's made programming on symfony very aggravating has been dealing with the forms.  Some sections of the forms are not well documented.  The main issue that I have with this at work is that we deal with GPS coordinates and the users enter their coordinates in degree-minute-seconds format but the database saves them in degree-decimal format.]]></description>
			<content:encoded><![CDATA[<p>One thing that&#8217;s made programming on symfony very aggravating has been dealing with the forms.  Some sections of the forms are not well documented.  The main issue that I have with this at work is that we deal with GPS coordinates and the users enter their coordinates in degree-minute-seconds format but the database saves them in degree-decimal format.</p>
<p>I had googled for a solution to this problem before, but had not found anything to guide me to the answer.  The couple answers I had found were not very clear on getting it to work.  Till I found <a title="jamescharlesworth.com" href="http://bit.ly/5YpPpu" target="_blank">this</a>.  Following these guidelines I got it to work on a test deployment of symfony.  Code below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Blog <span style="color: #000000; font-weight: bold;">extends</span> BaseBlog <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Initializes internal state of Blog object.
	 * @see        parent::__construct()
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Make sure that parent constructor is always invoked, since that</span>
		<span style="color: #666666; font-style: italic;">// is where any default values for this object are set.</span>
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">/*
	 * this function overrides the BaseBlog::save function to allow
	 * changes to be made to the object before saving to the database
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span>PropelPDO <span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setCommentCount</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'11'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2010/01/updating-symfony-form-values-after-submitting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>updating centOS 5 PHP install with mbstring &amp; APC</title>
		<link>http://techore.com/2009/12/updating-centos-5-php-install-with-mbstring-apc/</link>
		<comments>http://techore.com/2009/12/updating-centos-5-php-install-with-mbstring-apc/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 18:17:22 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[a2hosting]]></category>
		<category><![CDATA[alternative php cache]]></category>
		<category><![CDATA[apc]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[centos 5]]></category>
		<category><![CDATA[howtoforge]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[httpd-dev]]></category>
		<category><![CDATA[mbstring]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-dev]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[virtual private server]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=229</guid>
		<description><![CDATA[The default install on A2hosting's VPS does not have mbstring or APC installed by default.  I became aware of this as I was setting up symfony on the new server.  I googled around looking for a quick guide to install them.]]></description>
			<content:encoded><![CDATA[<p>The default install on <a title="A2hosting.com" href="http://www.a2hosting.com" target="_blank">A2hosting&#8217;s</a> <a title="techore.com" href="http://techore.com/wp/about/#VPS" target="_blank">VPS</a> does not have mbstring or APC installed by default.  I became aware of this as I was setting up symfony on the new server.  I googled around looking for a quick guide to install them.</p>
<p>mbstring is a straight-forward install:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> php-mbstring</pre></div></div>

<p>Easy.</p>
<p>Installing APC is a pretty simple affair with one big caveat at the end.  The guide that I found for installing APC is on <a title="howtoforge.com" href="http://bit.ly/4MkeRy" target="_blank">HowToForge</a>. The last two steps are particular to CentOS on A2hosting&#8217;s platform.</p>
<p>1.  Install PEAR.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> php-pear</pre></div></div>

<p>2.  Install php-dev &amp; httpd-dev.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> php-devel httpd-devel</pre></div></div>

<p>3.  Install group Development Tools</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum groupinstall <span style="color: #ff0000;">'Development Tools'</span></pre></div></div>

<p>4.  Install group Development Libraries</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yum groupinstall <span style="color: #ff0000;">'Development Libraries'</span></pre></div></div>

<p>5.  Install APC</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pecl <span style="color: #c20cb9; font-weight: bold;">install</span> apc</pre></div></div>

<p>6.  Reboot Apache</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">httpd <span style="color: #660033;">-k</span> restart</pre></div></div>

<p>7.  Error alerts you to SSLRandomSeed error.</p>
<p style="text-align: center;">
<div id="attachment_231" class="wp-caption aligncenter" style="width: 475px"><a href="http://techore.otterwedding.com/wp-content/uploads/2009/12/sslrandomseed_error.png" target="_blank"><img class="size-full wp-image-231 " title="sslrandomseed_error" src="http://techore.otterwedding.com/wp-content/uploads/2009/12/sslrandomseed_error.png" alt="SSLRandomSeed Error" width="465" height="114" /></a><p class="wp-caption-text">SSLRandomSeed Error</p></div>
<p>8.  Fix Centos Dev</p>
<p style="text-align: left;">
<div id="attachment_232" class="wp-caption aligncenter" style="width: 616px"><a href="http://techore.otterwedding.com/wp-content/uploads/2009/12/fix_centos_dev.png" target="_blank"><img class="size-full wp-image-232  " title="fix_centos_dev" src="http://techore.otterwedding.com/wp-content/uploads/2009/12/fix_centos_dev.png" alt="" width="606" height="310" /></a><p class="wp-caption-text">Fix CentOS Dev on A2hosting</p></div>
<p style="text-align: left;">It took me an hour last night to figure out the last step.  Without the last step there is no authentication so there is no SSH access.</p>
<p style="text-align: left;">Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/12/updating-centos-5-php-install-with-mbstring-apc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding javascript to symfony form field</title>
		<link>http://techore.com/2009/11/adding-javascript-to-symfony-form-field/</link>
		<comments>http://techore.com/2009/11/adding-javascript-to-symfony-form-field/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 21:27:25 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[onchange]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sfWidget]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=194</guid>
		<description><![CDATA[In the users table at my company's website there are fields for company, division, region, and location.  Since each level of the company organization affects all the lower categories I have to filter out the invalid choices when a higher level choice is selected.]]></description>
			<content:encoded><![CDATA[<p>In the users table at my company&#8217;s website there are fields for company, division, region, and location.  Since each level of the company organization affects all the lower categories I have to filter out the invalid choices when a higher level choice is selected.</p>
<p>I&#8217;ve implemented this on some forms that I&#8217;ve created manually on the site but not in any forms that I haven&#8217;t heavily modified from the stock symfony creation.  I started googling around to find a solution but could not find a simple explanation of how to do it.  I expected to find at least some information in one of symfony&#8217;s otherwise excellent tutorials, but alas, no.</p>
<p>I had a minor epiphany and went digging through the forms API that symfony provides and realized that I should easily be able to do this through the sfWidgetFormPropelChoice method.  The second parameter passed is the html attributes for the form field.  I thought I had seen a form post <a title="symfony forum" href="http://bit.ly/3f9j24" target="_blank">here</a> that said that I could add javascript code to the html attributes and not have it get converted into html entities.</p>
<p>I tried throwing a simple alert() inside the onchange attribute for my company box and wham! it worked!  So simple.  Code below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormPropelChoice<span style="color: #009900;">&#40;</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Company'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'add_empty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'onchange'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;filterBy('company', 'division', this.value, 'sf_guard_user_user_division_id');&quot;</span> <span style="color: #339933;">.</span>
			<span style="color: #0000ff;">&quot;filterBy('company', 'region', this.value, 'sf_guard_user_user_region_id');&quot;</span> <span style="color: #339933;">.</span>
			<span style="color: #0000ff;">&quot;filterBy('company', 'location', this.value, 'sf_guard_user_user_location_id');&quot;</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/11/adding-javascript-to-symfony-form-field/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ahhh, cronjobs!</title>
		<link>http://techore.com/2009/05/ahhh-cronjobs/</link>
		<comments>http://techore.com/2009/05/ahhh-cronjobs/#comments</comments>
		<pubDate>Tue, 26 May 2009 16:20:59 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=176</guid>
		<description><![CDATA[So I have a script designed to run whenever I need it to automatically get any new activities and save them to the local database waiting for the end-user.  I set it up to run every 15 minutes until I got the multitudes of old data into the new platform.  I'm talking ~170,000 activities, and each activity takes about 45-90 seconds to process.]]></description>
			<content:encoded><![CDATA[<p>One of the features of the new platform that I am working on is the ability to automatically retrieve all new seismic activities before the end-user posts that there has been an activity.  This will make the data transfer appear instantaneous to our clients and make us look all-around awesome.</p>
<p>So I have a script designed to run whenever I need it to automatically get any new activities and save them to the local database waiting for the end-user.  I set it up to run every 15 minutes until I got the multitudes of old data into the new platform.  I&#8217;m talking ~170,000 activities, and each activity takes about 45-90 seconds to process.</p>
<p>So below is my simple cronjob command to have it run every 15 minutes 24/7/365.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">15</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> php <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>runcron.php <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>cron<span style="color: #000000; font-weight: bold;">/</span>test_cron_log.log</pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/05/ahhh-cronjobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>modifying symfony database fields</title>
		<link>http://techore.com/2009/05/modifying-symfony-database-fields/</link>
		<comments>http://techore.com/2009/05/modifying-symfony-database-fields/#comments</comments>
		<pubDate>Fri, 22 May 2009 20:11:08 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[custom code]]></category>
		<category><![CDATA[manual database field changes]]></category>
		<category><![CDATA[modify symfony code]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=170</guid>
		<description><![CDATA[I am making progress on my company's new website.  I'm about 3 months in and will be launching the first version of the site in a few weeks.  So it was dismaying, to say the least, when I found that when I created the database schema I used the wrong data type for a few fields.]]></description>
			<content:encoded><![CDATA[<p>I am making progress on my company&#8217;s new website.  I&#8217;m about 3 months in and will be launching the first version of the site in a few weeks.  So it was dismaying, to say the least, when I found that when I created the database schema for the symfony project I used the wrong data type for a few fields.</p>
<p>In the current platform these particular fields are stored in MySQL &#8216;text&#8217; fields.  Simple, expands as needed, no problem.  I accidentally set these fields in the new schema as varchars.  My issue is that for most users, my varchar(32) field would be fine, but for that occasional user who uses lots of explosives &amp; different delays, this would mean a loss of data.  Not something I am very keen on.</p>
<p>I googled a bit and could not find any information on doing a reconfiguration of the database fields in symfony and I figured it wouldn&#8217;t be too difficult to manually convert the field to a blob and modify all the accessing functions.  In the end, I was right!  Assuming you don&#8217;t make any mistakes it is remarkably simple to change a database field from a varchar to a blob.  You only need to modify two files and four functions.  So, without further adieu, I give to you the code to make a blob field accessible instead of a varchar field for symfony through propel.</p>
<p>(Original code is commented out for reference)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// lib/model/om/BaseActivityInfo.php</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getActivityExplosiveType<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//		return $this-&gt;activity_explosive_type;</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_resource</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4096</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setActivityExplosiveType<span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// this is the new code (copied &amp; modified from setActivityExtra1) to set BLOB type</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Because BLOB columns are streams in PDO we have to assume that they are</span>
		<span style="color: #666666; font-style: italic;">// always modified when a new value is passed in.  For example, the contents</span>
		<span style="color: #666666; font-style: italic;">// of the stream itself may have changed externally.</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_resource</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://memory'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #009900;">&#41;</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: #666666; font-style: italic;">// it's already a stream</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modifiedColumns</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_EXPLOSIVE_TYPE</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
//	this is the original code for when the field was a simple varchar
		if ($v !== null) {
			$v = (string) $v;
		}
*/</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hydrate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #339933;">,</span> <span style="color: #000088;">$startcol</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rehydrate</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		try <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//   ... other field's code ...</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//		this is the original hydration code for the varchar type activity_explosive_type</span>
<span style="color: #666666; font-style: italic;">//			$this-&gt;activity_explosive_type = ($row[$startcol + 36] !== null) ? (string) $row[$startcol + 36] : null;</span>
<span style="color: #666666; font-style: italic;">//		this is the new hydration code for the blob type activity_explosive_type</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$startcol</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">36</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://memory'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$startcol</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">36</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #990000;">rewind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span><span style="color: #009900;">&#41;</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//  ... other field's code ...</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">resetModified</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNew</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rehydrate</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ensureConsistency</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: #666666; font-style: italic;">// FIXME - using NUM_COLUMNS may be clearer.</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$startcol</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">92</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 92 = ActivityInfoPeer::NUM_COLUMNS - ActivityInfoPeer::NUM_LAZY_LOAD_COLUMNS).</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			throw <span style="color: #000000; font-weight: bold;">new</span> PropelException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error populating ActivityInfo object&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">activity_explosive_type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">modifiedColumns</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_EXPLOSIVE_TYPE</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// setActivityExplosiveType()</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// lib/model/map/ActivityInfoMapBuilder.php</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doBuild<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbMap</span> <span style="color: #339933;">=</span> Propel<span style="color: #339933;">::</span><span style="color: #004000;">getDatabaseMap</span><span style="color: #009900;">&#40;</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">DATABASE_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$tMap</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbMap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTable</span><span style="color: #009900;">&#40;</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">TABLE_NAME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tMap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPhpName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ActivityInfo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$tMap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setClassname</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ActivityInfo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$tMap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUseIdGenerator</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$tMap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addPrimaryKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ID'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'INTEGER'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// ... other field's code ...</span>
<span style="color: #666666; font-style: italic;">//	this is the original code for the varchar type activity_explosive_type field</span>
<span style="color: #666666; font-style: italic;">//		$tMap-&gt;addColumn('ACTIVITY_EXPLOSIVE_TYPE', 'ActivityExplosiveType', 'VARCHAR', false, 32);</span>
<span style="color: #666666; font-style: italic;">// 	this is the new code for the blob type activity_explosive_type field</span>
		<span style="color: #000088;">$tMap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ACTIVITY_EXPLOSIVE_TYPE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ActivityExplosiveType'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'BLOB'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// ... other field's code ...</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// doBuild()</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// ActivityInfoMapBuilder</span></pre></div></div>

<p><strong>UPDATE: </strong><br />
I was doing some work with these form elements and realized that the Validators need to be modified as well.  It&#8217;s rather simple, all you need to do is change the validator to remove any size limitations and convert the Validator to a sfValidatorString from whatever type of sfValidator it was.  Code below:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// lib/form/base/BaseActivityInfoForm.class.php</span>
<span style="color: #339933;">...</span>other code<span style="color: #339933;">...</span>
<span style="color: #666666; font-style: italic;">// original code</span>
<span style="color: #666666; font-style: italic;">//      'activity_explosive_type'          =&gt; new sfValidatorString(array('max_length' =&gt; 32, 'required' =&gt; false)),</span>
      <span style="color: #0000ff;">'activity_explosive_type'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #666666; font-style: italic;">// original code</span>
<span style="color: #666666; font-style: italic;">//      'activity_explosive_make'          =&gt; new sfValidatorString(array('max_length' =&gt; 32, 'required' =&gt; false)),</span>
      <span style="color: #0000ff;">'activity_explosive_make'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #666666; font-style: italic;">// original code</span>
<span style="color: #666666; font-style: italic;">//      'activity_explosive_quantity'      =&gt; new sfValidatorNumber(array('required' =&gt; false)),</span>
      <span style="color: #0000ff;">'activity_explosive_quantity'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #339933;">...</span>other code<span style="color: #339933;">...</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/05/modifying-symfony-database-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Criteria::CUSTOM &#8211; the bane of my existence, until now&#8230;</title>
		<link>http://techore.com/2009/04/criteriacustom-the-bane-of-my-existence-until-now/</link>
		<comments>http://techore.com/2009/04/criteriacustom-the-bane-of-my-existence-until-now/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 20:32:29 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Criteria]]></category>
		<category><![CDATA[Criteria::CUSTOM]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[date function]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=160</guid>
		<description><![CDATA[A couple weeks ago I came across a query that I needed to write that would only retrieve the records that had the same date  as another table's record.  Since I am using propel, I looked for a simple way to format the datetime field to just match the dates in the query so that only the appropriate records would be returned.  I googled for a long time, not reaching any solution.]]></description>
			<content:encoded><![CDATA[<p>A couple weeks ago I came across a query that I needed to write that would only retrieve the records that had the same date  as another table&#8217;s record.  Since I am using propel, I looked for a simple way to format the datetime field to just match the dates in the query so that only the appropriate records would be returned.  I googled for a long time, not reaching any solution.</p>
<p>I ended up with a stopgap measure to get me by until I could focus more time on the problem.  I iterated through the results and used php to compare the dates and drop the nonequal date records.  Today the problem came to a head where I could not move forward with my work until I solved the issue.  Since I&#8217;m using mysql and propel, I ended up creating a custom criteria using the mysql &#8216;DATE&#8217; function.  I know this is suboptimal in that my query is now tied to mysql, but I really don&#8217;t expect to be changing databases soon, or ever.</p>
<p>Most of the solutions that I found online would not work with the DATE function for one reason or another (another = I couldn&#8217;t figure it out).  I finally found my solution in the symfony forums (can you believe it!?!?!) <a title="symfony - forums" href="http://forum.symfony-project.org/index.php/m/66704/?srch=Criteria%3A%3ACUSTOM#msg_66704" target="_blank">here</a>.  For some reason google failed me on this one.  So out of the billions of pages online I had to find the one (1) that had my solution.  Luckily time_to_find_solution &lt; losing_my_mind.  So the very simple solution is this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_EVENT_TIME</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'DATE('</span><span style="color: #339933;">.</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_EVENT_TIME</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')= DATE('</span><span style="color: #339933;">.</span>ActivitySeismoInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ASI_EVENT_TIME</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">,</span> Criteria<span style="color: #339933;">::</span><span style="color: #004000;">CUSTOM</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/04/criteriacustom-the-bane-of-my-existence-until-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>adding OR conditional to a symfony query</title>
		<link>http://techore.com/2009/04/adding-or-conditional-to-a-symfony-query/</link>
		<comments>http://techore.com/2009/04/adding-or-conditional-to-a-symfony-query/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 19:02:20 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Criteria]]></category>
		<category><![CDATA[Criterion]]></category>
		<category><![CDATA[OR statement]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=147</guid>
		<description><![CDATA[I had to do some looking to find how to do an 'or' statement in symfony with propel.  I found out at a google's group here and the api documentation from propel is here.  Once I found the information it was surprisingly easy.  Below is the code I ended up using to select records either updated in the last two weeks OR activities that are delayed AND activities that the posting times are NULL (implying they are not posted yet).]]></description>
			<content:encoded><![CDATA[<p>I had to do some looking to find how to do an &#8216;or&#8217; statement in symfony with propel.  I found out at a google&#8217;s group <a title="Google Groups for symfony" href="http://groups.google.com/group/symfony-users/browse_thread/thread/d838d6477b1347b3?fwc=1" target="_blank">here</a> and the api documentation from propel is <a title="Propel Criteria" href="http://propel.phpdb.org/docs/api/1.3/runtime/propel-util/Criteria.html" target="_blank">here</a>.  Once I found the information it was surprisingly easy.  Below is the code I ended up using to select records either updated in the last two weeks OR activities that are delayed AND activities that the posting times are NULL (implying they are not posted yet).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddDescendingOrderByColumn</span><span style="color: #009900;">&#40;</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_EVENT_TIME</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$criterion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewCriterion</span><span style="color: #009900;">&#40;</span>
ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">UPDATED_AT</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1209600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> Criteria<span style="color: #339933;">::</span><span style="color: #004000;">GREATER_THAN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOr</span><span style="color: #009900;">&#40;</span>
     <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewCriterion</span><span style="color: #009900;">&#40;</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_DELAYED</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> Criteria<span style="color: #339933;">::</span><span style="color: #004000;">EQUAL</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAnd</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNewCriterion</span><span style="color: #009900;">&#40;</span>ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">ACTIVITY_POST_TIME</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> Criteria<span style="color: #339933;">::</span><span style="color: #004000;">ISNULL</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criterion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pending_activities</span> <span style="color: #339933;">=</span> ActivityInfoPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/04/adding-or-conditional-to-a-symfony-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>setting memory_limit for symfony propel:build-model</title>
		<link>http://techore.com/2009/03/setting-memory_limit-for-symfony-propelbuild-model/</link>
		<comments>http://techore.com/2009/03/setting-memory_limit-for-symfony-propelbuild-model/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 19:41:46 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[build-model]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[ini_set]]></category>
		<category><![CDATA[memory_limit]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://techore.com/wp/?p=123</guid>
		<description><![CDATA[A few days ago my company got our production server for the upcoming website up and running so that I can start working with it.  Since this server is being hosted at another office out of state I am learning how to deploy symfony on a server that I don't have physical access to.]]></description>
			<content:encoded><![CDATA[<p>A few days ago my company got our production server for the upcoming website up and running so that I can start working with it.  Since this server is being hosted at another office out of state I am learning how to deploy symfony on a server that I don&#8217;t have physical access to.</p>
<p>When doing all my previous work (all 3 months!) with symfony, I have either worked on it on my local machine or on a small dev server in our server closet.  The main difference on this new server is that I cannot update the php.ini file whenever I choose.  I am able to have it modified when there is a long-term need (ie- setting magic_quotes_gpc &amp; short_open_tag to Off).  But when running the build commands for the new platform I need a good bit of memory.  The propel:build-model action takes more than 32 MB of memory and since I couldn&#8217;t change the php.ini file I had to find a way around it.</p>
<p>I discovered that the symfony .bat file that is in the symfony distro has php in it and I was able to simply use the ini_set function to set the memory limit to 64MB while executing any <a title="command-line interface" href="http://techore.com/wp/about/#cli" target="_blank">CLI</a> symfony scripts.</p>
<p>Till Next Time</p>
]]></content:encoded>
			<wfw:commentRss>http://techore.com/2009/03/setting-memory_limit-for-symfony-propelbuild-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
