<?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>Stereo Interactive &#38; Design &#187; PHP</title>
	<atom:link href="http://stereointeractive.com/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereointeractive.com/blog</link>
	<description>Development Blog</description>
	<lastBuildDate>Wed, 07 Jul 2010 19:16:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wordpress get post images and the_post_thumbnail caption</title>
		<link>http://stereointeractive.com/blog/2010/02/12/wordpress-get-post-images-and-the_post_thumbnail-caption/</link>
		<comments>http://stereointeractive.com/blog/2010/02/12/wordpress-get-post-images-and-the_post_thumbnail-caption/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 23:11:40 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=391</guid>
		<description><![CDATA[Before the_post_thumbnail was available, here is how I would fetch an array of images that were attached to a post in wordpress:


&#60;?php $images = &#38;get_children&#40;'post_type=attachment&#38;post_mime_type=image&#38;orderby=menu_order&#38;order=ASC&#38;post_parent='.$post-&#62;ID&#41;;
    if &#40;$images&#41;:
    $image = current&#40;$images&#41;; $imageData = wp_get_attachment_image_src&#40;$image-&#62;ID&#41;; ?&#62;
    &#60;img src=&#34;&#60;?php echo $imageData&#91;0&#93; ?&#62;&#34; alt=&#34;&#60;?php the_title&#40;&#41; ?&#62;&#34; /&#62;
    [...]]]></description>
			<content:encoded><![CDATA[<p>Before <code>the_post_thumbnail</code> was available, here is how I would fetch an array of images that were attached to a post in wordpress:<br />
<span id="more-391"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span> <span class="re0">$images</span> <span class="sy0">=</span> <span class="sy0">&amp;</span>get_children<span class="br0">&#40;</span><span class="st_h">'post_type=attachment&amp;post_mime_type=image&amp;orderby=menu_order&amp;order=ASC&amp;post_parent='</span><span class="sy0">.</span><span class="re0">$post</span><span class="sy0">-&gt;</span><span class="me1">ID</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$images</span><span class="br0">&#41;</span><span class="sy0">:</span>
    <span class="re0">$image</span> <span class="sy0">=</span> <span class="kw3">current</span><span class="br0">&#40;</span><span class="re0">$images</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="re0">$imageData</span> <span class="sy0">=</span> wp_get_attachment_image_src<span class="br0">&#40;</span><span class="re0">$image</span><span class="sy0">-&gt;</span><span class="me1">ID</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="sy1">?&gt;</span>
    &lt;img src=&quot;<span class="kw2">&lt;?php</span> <span class="kw1">echo</span> <span class="re0">$imageData</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="sy1">?&gt;</span>&quot; alt=&quot;<span class="kw2">&lt;?php</span> the_title<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy1">?&gt;</span>&quot; /&gt;
    <span class="kw2">&lt;?php</span> <span class="kw1">endif</span> <span class="sy1">?&gt;</span>
&lt;!-- image title: $image-&gt;post_title, caption: $image-&gt;post_excerpt, description: $image-&gt;post_content --&gt;</pre></div></div>

<p>Usually we&#8217;d use this just to pull out the first image attachment to a post and use this in a special place in our template. Now that there is built-in post thumbnail support, we wanted to use this feature but also still have the ability to display the selected thumbnail&#8217;s caption information. <code>the_post_thumbnail</code> only returns the image tag, so here is our custom filter (inside our template&#8217;s functions.php file) that adds our caption:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">function</span> monahans_thumbnail_caption<span class="br0">&#40;</span><span class="re0">$html</span><span class="sy0">,</span> <span class="re0">$post_id</span><span class="sy0">,</span> <span class="re0">$post_thumbnail_id</span><span class="sy0">,</span> <span class="re0">$size</span><span class="sy0">,</span> <span class="re0">$attr</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
  <span class="re0">$attachment</span> <span class="sy0">=&amp;</span> get_post<span class="br0">&#40;</span><span class="re0">$post_thumbnail_id</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="co1">// post_title =&gt; image title</span>
  <span class="co1">// post_excerpt =&gt; image caption</span>
  <span class="co1">// post_content =&gt; image description</span>
&nbsp;
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_excerpt</span> <span class="sy0">||</span> <span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_content</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$html</span> <span class="sy0">.=</span> <span class="st_h">'&lt;p class=&quot;thumbcaption&quot;&gt;'</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_excerpt</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="re0">$html</span> <span class="sy0">.=</span> <span class="st_h">'&lt;span class=&quot;captitle&quot;&gt;'</span><span class="sy0">.</span><span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_excerpt</span><span class="sy0">.</span><span class="st_h">'&lt;/span&gt; '</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="re0">$html</span> <span class="sy0">.=</span> <span class="re0">$attachment</span><span class="sy0">-&gt;</span><span class="me1">post_content</span><span class="sy0">.</span><span class="st_h">'&lt;/p&gt;'</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">return</span> <span class="re0">$html</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
add_action<span class="br0">&#40;</span><span class="st_h">'post_thumbnail_html'</span><span class="sy0">,</span> <span class="st_h">'monahans_thumbnail_caption'</span><span class="sy0">,</span> <span class="kw4">null</span><span class="sy0">,</span> <span class="nu0">5</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>The result of this filter is now anytime we call <code>the_post_thumbnail</code> in our template, the html will come back with our image caption, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/02/12/wordpress-get-post-images-and-the_post_thumbnail-caption/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>http_build_query</title>
		<link>http://stereointeractive.com/blog/2009/08/17/http_build_query/</link>
		<comments>http://stereointeractive.com/blog/2009/08/17/http_build_query/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 05:03:06 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=301</guid>
		<description><![CDATA[I can never remember the name of this function. I always google and search the php docs for things like &#8216;php query params&#8217;, &#8216;php url parameters&#8217;, &#8216;php query string from array&#8217;, &#8216;php http query params&#8217;, and I even saw &#8220;php array to post string&#8221; and for some reason this page just never comes up. Yes, [...]]]></description>
			<content:encoded><![CDATA[<p>I can never remember the name of this function. I always google and search the php docs for things like &#8216;php query params&#8217;, &#8216;php url parameters&#8217;, &#8216;php query string from array&#8217;, &#8216;php http query params&#8217;, and I even saw &#8220;php array to post string&#8221; and for some reason this page just never comes up. Yes, this post is a selfish way for me to find this next year when I search my blog for this post!</p>
<p><a href="http://www.php.net/manual/en/function.http-build-query.php">http://www.php.net/manual/en/function.http-build-query.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/08/17/http_build_query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony configuration settings, &#8220;default&#8221; versus &#8220;all&#8221;</title>
		<link>http://stereointeractive.com/blog/2009/08/10/symfony-securityyml-default-versus-all/</link>
		<comments>http://stereointeractive.com/blog/2009/08/10/symfony-securityyml-default-versus-all/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 15:27:28 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=295</guid>
		<description><![CDATA[It&#8217;s hard to keep track of the difference between the &#8220;all&#8221; parameter heading and the &#8220;default&#8221; parameter heading in your security configuration files. The way to remember it is that &#8220;default&#8221; is just that &#8212; a value for when there are no other values set, including one for &#8220;all&#8221;.  
The way symfony parses its [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s hard to keep track of the difference between the &#8220;all&#8221; parameter heading and the &#8220;default&#8221; parameter heading in your security configuration files. The way to remember it is that &#8220;default&#8221; is just that &#8212; a value for when there are no other values set, including one for &#8220;all&#8221;.  <span id="more-295"></span></p>
<p>The way symfony parses its configuration yml files, it does a deep merge and makes the settings for &#8220;all&#8221; override the settings for &#8220;default&#8221;. So if you had an &#8220;all&#8221; setting in your application&#8217;s security.yml, and then a &#8220;default&#8221; setting in your module, the &#8220;all&#8221; setting would still take precedence even though mentally we like to think of module settings always overriding what is found in the application-wide files. </p>
<p>Here is the snippet in of code that actually does this processing, (it&#8217;s in a file called sfSecurityConfigHandler.class.php). Here, $myConfig is an array with action names as the keys, and the value is an array containing the &#8220;is_secure&#8221; parameter along with any specific credentials required.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'all'</span><span class="br0">&#93;</span> <span class="sy0">=</span> sfToolkit<span class="sy0">::</span><span class="me2">arrayDeepMerge</span><span class="br0">&#40;</span>
      <span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'default'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> <span class="kw3">is_array</span><span class="br0">&#40;</span><span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'default'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> ? <span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'default'</span><span class="br0">&#93;</span> <span class="sy0">:</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
      <span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'all'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> <span class="kw3">is_array</span><span class="br0">&#40;</span><span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'all'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> ? <span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'all'</span><span class="br0">&#93;</span> <span class="sy0">:</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>So, when symfony is parsing all of those security.yml files, you end up with a bunch of entries for all of your various actions:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'login'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'is_secure'</span> <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="re0">$myConfig</span><span class="br0">&#91;</span><span class="st_h">'mySecureAction'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'is_secure'</span> <span class="sy0">=&gt;</span> <span class="kw4">true</span><span class="sy0">,</span> <span class="st_h">'credentials'</span> <span class="sy0">=&gt;</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="sy0">...</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>and then symfony creates the &#8220;all&#8221; setting, based on what it finds for &#8220;default&#8221; and &#8220;all&#8221;, which it will use for any action that doesn&#8217;t have an explicit security setting. This $myConfig array is what eventually gets saved into the auto-generated [module]_config_security.yml.php files inside your cache directory.</p>
<p>So, if you are having trouble getting the right javascript or stylesheets to load in your view, or having trouble securing a page even though you are certain it&#8217;s listed in your security.yml file, check to see if there is an existing &#8220;all&#8221; configuration that might be overriding your local &#8220;default&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/08/10/symfony-securityyml-default-versus-all/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP import excel (xls) files to array or csv</title>
		<link>http://stereointeractive.com/blog/2009/07/29/php-import-excel-xls-files-to-array-or-csv/</link>
		<comments>http://stereointeractive.com/blog/2009/07/29/php-import-excel-xls-files-to-array-or-csv/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 22:51:14 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=273</guid>
		<description><![CDATA[How have I never seen this before today?
PHPExcel
I&#8217;ve only been working with it for a few hours but it&#8217;s amazing. It can read and write from many different formats. 

Output your spreadsheet object to different file formats

Excel 2007 (spreadsheetML)
BIFF8 (Excel 97 and higher)
PHPExcel Serialized Spreadsheet
CSV (Comma Separated Values)
HTML
PDF

Read different file formats into your spreadsheet object

Excel [...]]]></description>
			<content:encoded><![CDATA[<p>How have I never seen this before today?</p>
<p><a href="http://phpexcel.codeplex.com/">PHPExcel</a></p>
<p>I&#8217;ve only been working with it for a few hours but it&#8217;s amazing. It can read and write from many different formats. </p>
<blockquote><p>
<strong>Output your spreadsheet object to different file formats</strong></p>
<ul>
<li>Excel 2007 (spreadsheetML)</li>
<li>BIFF8 (Excel 97 and higher)</li>
<li>PHPExcel Serialized Spreadsheet</li>
<li>CSV (Comma Separated Values)</li>
<li>HTML</li>
<li>PDF</li>
</ul>
<p><strong>Read different file formats into your spreadsheet object</strong></p>
<ul>
<li>Excel 2007 (spreadsheetML)</li>
<li>BIFF5 (Excel 5.0 / Excel 95), BIFF8 (Excel 97 and higher)</li>
<li>PHPExcel Serialized Spreadsheet</li>
<li>CSV (Comma Separated Values)</li>
</ul>
</blockquote>
<p>I am very excited about this. Another honorable mention is <a href="http://code.google.com/p/php-excel-reader/">php-excel-reader</a> which might be worth a look if you just want something a bit more simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/07/29/php-import-excel-xls-files-to-array-or-csv/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Propel criteria on custom columns (with addAsColumn)</title>
		<link>http://stereointeractive.com/blog/2009/07/21/propel-criteria-on-custom-columns-with-addascolumn/</link>
		<comments>http://stereointeractive.com/blog/2009/07/21/propel-criteria-on-custom-columns-with-addascolumn/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 22:06:01 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Propel]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=256</guid>
		<description><![CDATA[This still trips me up. If you are using propel criteria objects and want to add a condition on a custom column, you have to do a bit of trickery to get it working just right.  
Let&#8217;s say you want to add a custom column to your query, let&#8217;s say &#8220;points remaining&#8221; for the [...]]]></description>
			<content:encoded><![CDATA[<p>This still trips me up. If you are using propel criteria objects and want to add a condition on a custom column, you have to do a bit of trickery to get it working just right.  <span id="more-256"></span></p>
<p>Let&#8217;s say you want to add a custom column to your query, let&#8217;s say &#8220;points remaining&#8221; for the sake of example.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">addAsColumn</span><span class="br0">&#40;</span><span class="st_h">'points_remaining'</span><span class="sy0">,</span> <span class="st_h">'('</span><span class="sy0">.</span>UserPointsPeer<span class="sy0">::</span><span class="me2">TOTAL_POINTS</span><span class="sy0">.</span><span class="st_h">' - '</span><span class="sy0">.</span>UserPointsPeer<span class="sy0">::</span><span class="me2">POINTS_EARNED</span><span class="sy0">.</span><span class="st_h">')'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p>And now you want to limit your query to just users who have a certain number of points remaining. Since this is on a custom column, you have to use the <code>addHaving()</code> method. This gets a bit more tricky because when adding criteria based on custom columns, Propel wants to generate criterion objects using column names which include the column&#8217;s table name and dot separator. So, we have to rely on the <code>Criteria::CUSTOM</code> functionality. No doubt this is a hack and it completely circumvents any built-in query escaping that is <strong>essential</strong>, but if you are careful about sanitizing your input, you can do the following. Note this code sample assumes that <code>$pointsFilter['from']</code> and <code>$pointsFilter['to']</code> contain the GET or POST input parameters for use in your query:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="co1">// first version where we want to fetch a custom column</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span><span class="sy0">;</span>
  <span class="re0">$criterion</span> <span class="sy0">=</span> <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">getNewCriterion</span><span class="br0">&#40;</span>UserPointsPeer<span class="sy0">::</span><span class="me2">ID</span><span class="sy0">,</span> <span class="st_h">'points_remaining &gt;= '</span><span class="sy0">.</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span><span class="sy0">,</span> Criteria<span class="sy0">::</span><span class="me2">CUSTOM</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="sy0">;</span>
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$criterion</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$criterion</span><span class="sy0">-&gt;</span><span class="me1">addAnd</span><span class="br0">&#40;</span><span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">getNewCriterion</span><span class="br0">&#40;</span>UserPointsPeer<span class="sy0">::</span><span class="me2">ID</span><span class="sy0">,</span> <span class="st_h">'points_remaining &lt;= '</span><span class="sy0">.</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="sy0">,</span> Criteria<span class="sy0">::</span><span class="me2">CUSTOM</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
    <span class="re0">$criterion</span> <span class="sy0">=</span> <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">getNewCriterion</span><span class="br0">&#40;</span>UserPointsPeer<span class="sy0">::</span><span class="me2">ID</span><span class="sy0">,</span> <span class="st_h">'points_remaining &lt;= '</span><span class="sy0">.</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="sy0">,</span> Criteria<span class="sy0">::</span><span class="me2">CUSTOM</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$criterion</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">addHaving</span><span class="br0">&#40;</span><span class="re0">$criterion</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Note that we have to use <code>addHaving()</code> to add our condition to our custom column.</p>
<p>If you don&#8217;t need to retrieve the custom column in your query but still want to limit your results on that criteria, you can use the <code>add()</code> method, but you have to change it up a bit:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="co1">// second version without adding a custom column</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span><span class="sy0">;</span>
  <span class="re0">$criterion</span> <span class="sy0">=</span> <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">getNewCriterion</span><span class="br0">&#40;</span>
    UserPointsPeer<span class="sy0">::</span><span class="me2">ID</span><span class="sy0">,</span> <span class="co1">// can be any column in your table, really</span>
    <span class="st_h">'('</span><span class="sy0">.</span>CurriculumPeer<span class="sy0">::</span><span class="me2">TOTAL_POINTS</span><span class="sy0">.</span><span class="st_h">' - '</span><span class="sy0">.</span>UserPointsPeer<span class="sy0">::</span><span class="me2">POINTS_EARNED</span><span class="sy0">.</span><span class="st_h">') &gt;= '</span><span class="sy0">.</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'from'</span><span class="br0">&#93;</span><span class="sy0">,</span> 
    Criteria<span class="sy0">::</span><span class="me2">CUSTOM</span>
  <span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="br0">&#40;</span>int<span class="br0">&#41;</span> <span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="sy0">;</span>
  <span class="re0">$pointsFilterToCriterion</span> <span class="sy0">=</span> <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">getNewCriterion</span><span class="br0">&#40;</span>
    UserPointsPeer<span class="sy0">::</span><span class="me2">ID</span><span class="sy0">,</span> 
    <span class="st_h">'('</span><span class="sy0">.</span>CurriculumPeer<span class="sy0">::</span><span class="me2">TOTAL_POINTS</span><span class="sy0">.</span><span class="st_h">' - '</span><span class="sy0">.</span>UserPointsPeer<span class="sy0">::</span><span class="me2">POINTS_EARNED</span><span class="sy0">.</span><span class="st_h">') &lt;= '</span><span class="sy0">.</span><span class="re0">$pointsFilter</span><span class="br0">&#91;</span><span class="st_h">'to'</span><span class="br0">&#93;</span><span class="sy0">,</span>
    Criteria<span class="sy0">::</span><span class="me2">CUSTOM</span>
  <span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$criterion</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re0">$criterion</span><span class="sy0">-&gt;</span><span class="me1">addAnd</span><span class="br0">&#40;</span><span class="re0">$pointsFilterToCriterion</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
    <span class="re0">$criterion</span> <span class="sy0">=</span> <span class="re0">$pointsFilterToCriterion</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$criterion</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="re0">$c</span><span class="sy0">-&gt;</span><span class="me1">add</span><span class="br0">&#40;</span><span class="re0">$criterion</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Note that in this example I&#8217;m typecasting our input parameters are integers, but you could mysql_real_escape_string() or any other sanitizing method you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/07/21/propel-criteria-on-custom-columns-with-addascolumn/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Doctrine: Fetching related objects with hasOne relationship or one-to-zero-or-one</title>
		<link>http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/</link>
		<comments>http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 18:38:35 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=240</guid>
		<description><![CDATA[People new to the Doctrine ORM have a hard time understanding the magic that happens behind the scenes when you want to fetch a related object through a has-one-or-zero relationship. Looking through the doctrine-user group, it&#8217;s clear there is a lot confusion on this to newcomers, especially if you are coming over from Propel or [...]]]></description>
			<content:encoded><![CDATA[<p>People new to the Doctrine ORM have a hard time understanding the magic that happens behind the scenes when you want to fetch a related object through a has-one-or-zero relationship. Looking through the doctrine-user group, it&#8217;s clear there is a lot confusion on this to newcomers, especially if you are coming over from Propel or other ORMs. It can be a pretty big conceptual change to how things are done.<br />
<span id="more-240"></span></p>
<p>To use an example off of the doctrine-user group, imagine you have a Content object and this may or may not have a related Metadata record.</p>
<p>If you are familiar with Propel, then if you had your hydrated $content object, you could do</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="co1">// with propel:</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$metadata</span> <span class="sy0">=</span> <span class="re0">$content</span><span class="sy0">-&gt;</span><span class="me1">getMetadata</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="co1">// do something with the related $metadata</span>
<span class="br0">&#125;</span></pre></div></div>

<p>and getMetadata() would return NULL if there was no related record to be found.</p>
<p><strong>Doctrine will automatically create an empty related object if you request one</strong>, so calling <code>$content->Metadata</code> or <code>$content['Metadata']</code> or $content->getMetadata() will always return a Metadata object, even if it does not exist in the database. So, you can&#8217;t rely on the same trick above to see if a related object exists. </p>
<p>So, how do you check if a related object actually exists? The first way, and my favorite, is using the <code>exists()</code> method to check if the related object is persistent (i.e. the object is saved in the DB).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="co1">// with doctrine </span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$content</span><span class="sy0">-&gt;</span><span class="me1">Metadata</span><span class="sy0">-&gt;</span><span class="me1">exists</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> 
  <span class="co1">// related metadata exists for this $content object</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Using <code>isset()</code> will check if the related object has been hydrated/ loaded, but it will not do a query against the database to see if it exists there. So, if you fetch a Content object and do not do any joins in your query to join the related Metadata objects, then isset(), either by doing <code>isset($business->Metadata)</code> or <code>$business->isset('Metadata')</code> will *always* return false.</p>
<p>If your foreign key to the related object exists in your parent record (if content has a metadata_id field) you can always check the value of <code>$content['metadata_id']</code>. This will not work if the foreign key exists only in your metadata table (metadata has a column content_id, but content does not have a metadata_id column).</p>
<p>I think if you really wanted to do it right, if you expect to be checking for the existence of a related object (&#8220;Metadata&#8221;) on your collection of core objects (&#8220;Content&#8221;), you should do a join in your query so you don&#8217;t have to hit the database for every single Content record fetched to see if a related Metadata record exists.</p>
<p>Here are a few threads on this subject in the doctrine-user group:</p>
<ul>
<li><a href="http://groups.google.com/group/doctrine-user/browse_thread/thread/75ba51a6c59685cb">Call $record->Related without creating new object</a></li>
<li><a href="http://groups.google.com/group/doctrine-user/browse_thread/thread/cfd24581e03322eb">hasOne relationship</a></li>
<li><a href="http://groups.google.com/group/doctrine-user/browse_thread/thread/de79d55b0af80a1d">Awkward handling of One-to-Zero-or-One relationships in Doctrine</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/07/16/php-doctrine-fetching-related-objects-with-hasone-relationship-or-one-to-zero-or-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php isset and not empty</title>
		<link>http://stereointeractive.com/blog/2009/07/11/php-isset-and-not-empty/</link>
		<comments>http://stereointeractive.com/blog/2009/07/11/php-isset-and-not-empty/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 07:52:21 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=229</guid>
		<description><![CDATA[I find myself doing this a lot:

if &#40;isset&#40;$myarray&#91;'foo'&#93;&#41; &#38;&#38; $myarray&#91;'foo'&#93;&#41;&#41; &#123;
  // do something
&#125;

But I thought there had to be a better way, and one that would not throw undefined errors. A quick google search came up with a few good hits, include the PHP manual page for empty().
The manual says that when using [...]]]></description>
			<content:encoded><![CDATA[<p>I find myself doing this a lot:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$myarray</span><span class="br0">&#91;</span><span class="st_h">'foo'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> <span class="re0">$myarray</span><span class="br0">&#91;</span><span class="st_h">'foo'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="co1">// do something</span>
<span class="br0">&#125;</span></pre></div></div>

<p>But I thought there had to be a better way, and one that would not throw undefined errors. A quick google search came up with a few good hits, include the <a href="http://php.net/manual/en/function.empty.php">PHP manual page for empty()</a>.</p>
<p>The manual says that when using empty(), no warnings are thrown when a variable is not set. It will return true in the following cases:</p>
<blockquote><p>
&#8220;&#8221; (an empty string)<br />
0 (0 as an integer)<br />
&#8220;0&#8243; (0 as a string)<br />
NULL<br />
FALSE<br />
array() (an empty array)<br />
var $var; (a variable declared, but without a value in a class)
</p></blockquote>
<p>Keep in mind that an object with no properties is not considered empty().</p>
<p>Now, we can make our code a bit more beautiful:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">empty</span><span class="br0">&#40;</span><span class="re0">$myarray</span><span class="br0">&#91;</span><span class="st_h">'foo'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="co1">// do something</span>
<span class="br0">&#125;</span></pre></div></div>

<p>I&#8217;ve known about empty() for a long time, but for some reason always seemed to choose isset() over empty(), even in cases like this. </p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/07/11/php-isset-and-not-empty/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Symfony Propel Enum types</title>
		<link>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/</link>
		<comments>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 19:46:13 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Propel]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=210</guid>
		<description><![CDATA[Propel does not support enum column types in its schemas, since the enum type is not support across all database types. There are a few ways around this.
1) Use another table to list the enum options. Pros: most flexible. Works nicely within symfony. Cons: means more joins in your queries. 
2) Use enum anyway. You [...]]]></description>
			<content:encoded><![CDATA[<p>Propel does not support enum column types in its schemas, since the enum type is not support across all database types. There are a few ways around this.<span id="more-210"></span></p>
<p>1) Use another table to list the enum options. Pros: most flexible. Works nicely within symfony. Cons: means more joins in your queries. </p>
<p>2) Use enum anyway. You can add custom column types using a little known trick in your schema:</p>
<pre class="code" type="php">
status:
  id:
  name: { type: varchar, sqltype:enum, size: "'inactive','active'", default: inactive }
</pre>
<p>Pros: You get your enum. Cons: Not very portable, a bit of a hack.</p>
<p>3) Simulate an enum column using your model. I typically end up doing this for columns that have a finite number of defined options *that will not change*. Pros: Fast. Cons: Not as flexible as optino 1. Example:</p>
<pre class="code" type="php">

class UserProfilePeer extends BaseUserProfilePeer
{
  static protected $USER_TYPE_INTEGERS = array('student', 'supervisor', 'coordinator', 'researcher', 'admin');
  static protected $USER_TYPE_VALUES = null;

  /**
   * Returns a user type label from an index value.
   *
   * @param integer $index
   * @return string user type label
   * @author Scott Meves
   */
  static public function getUserTypeFromIndex($index)
  {
    return self::$USER_TYPE_INTEGERS[$index];
  }

  /**
   * Returns the user type index from a string value
   *
   * @param string $value
   * @return integer $index
   * @author Scott Meves
   */
  static public function getUserTypeFromValue($value)
  {
    if (!self::$USER_TYPE_VALUES)
    {
      self::$USER_TYPE_VALUES = array_flip(self::$USER_TYPE_INTEGERS);
    }

    $values = strtolower($value);

    if (!isset(self::$USER_TYPE_VALUES[$value]))
    {
      throw new PropelException(sprintf('User type cannot take "%s" as a value', $value));
    }

    return self::$USER_TYPE_VALUES[strtolower($value)];
  }

  public static function getUserTypeOptions()
  {
    return self::$USER_TYPE_INTEGERS;
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Symfony: How to render a partial from an action</title>
		<link>http://stereointeractive.com/blog/2009/03/11/symfony-how-to-render-a-partial-from-an-action/</link>
		<comments>http://stereointeractive.com/blog/2009/03/11/symfony-how-to-render-a-partial-from-an-action/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 06:55:27 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=177</guid>
		<description><![CDATA[If you ever find yourself wanting to return the contents of a partial as the entire response for an action, Symfony makes it possible. Using symfony partials with ajax, you have a lot of options of how you want to arrange your templates, but here I&#8217;ll show you what has worked best for me.
Oftentimes I [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever find yourself wanting to return the contents of a partial as the entire response for an action, Symfony makes it possible. Using symfony partials with ajax, you have a lot of options of how you want to arrange your templates, but here I&#8217;ll show you what has worked best for me.</p>
<p>Oftentimes I find myself wanting to return the contents of a partial as the entire response for an ajax request. I do this a lot when I am already using a partial in my template, and then I want to replace that section with the results of an ajax call. We already have a partial set up to display that content, so we might as well reuse it when we have to refresh that area with new content. <span id="more-177"></span></p>
<p>Imagine we have a page that presents a list of articles. In the right sidebar we&#8217;d like to feature a preview of the first article. We&#8217;d also like to allow a &#8220;quick look&#8221; for the other articles. Clicking on the quick look button should load a preview of the selected article in the right sidebar, replaced the default preview.</p>
<p>To do this, I set up a partial that contains the article preview. In the default list template (e.g. listSuccess.php) I include the partial along with the featured article.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span> include_partial<span class="br0">&#40;</span><span class="st_h">'preview'</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'article'</span><span class="sy0">=&gt;</span><span class="re0">$article</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy1">?&gt;</span></pre></div></div>

<p>Then, when someone clicks the quick look button, we want to make an ajax call that returns the new preview content with that particular article. Our action might look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">public</span> <span class="kw2">function</span> executeLoadPreview<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
  <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">article</span> <span class="sy0">=</span> ArticlePeer<span class="sy0">::</span><span class="me2">retrieveByPk</span><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">getRequestParamer</span><span class="br0">&#40;</span><span class="st_h">'articleId'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>The most obvious thing to do now would be to set up a standard loadPreviewSuccess.php tempate and within that template simply include the partial just as you would normally.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">// loadPreviewSuccess.php
<span class="kw2">&lt;?php</span> include_partial<span class="br0">&#40;</span><span class="st_h">'preview'</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'article'</span><span class="sy0">=&gt;</span><span class="re0">$article</span><span class="br0">&#41;</span> <span class="sy1">?&gt;</span></pre></div></div>

<p>This is totally fine, and you may like it, but there is another way to do it. We can just render the contents of the partial directly from our action. Here is what it looks like. (Note that I turn off the web debugging so that it doesn&#8217;t render within the ajax call!)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">public</span> <span class="kw2">function</span> executeLoadPreview<span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
  sfConfig<span class="sy0">::</span><span class="me2">set</span><span class="br0">&#40;</span><span class="st_h">'sf_web_debug'</span><span class="sy0">,</span> <span class="kw4">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
  sfLoader<span class="sy0">::</span><span class="me2">loadHelpers</span><span class="br0">&#40;</span><span class="st_h">'Partial'</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="re0">$article</span> <span class="sy0">=</span> ArticlePeer<span class="sy0">::</span><span class="me2">retrieveByPk</span><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">getRequestParamer</span><span class="br0">&#40;</span><span class="st_h">'articleId'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
  <span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">renderText</span><span class="br0">&#40;</span>get_partial<span class="br0">&#40;</span><span class="st_h">'preview'</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'article'</span> <span class="sy0">=&gt;</span> <span class="re0">$article</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Nice! </p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/03/11/symfony-how-to-render-a-partial-from-an-action/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Uploading a file with Symfony 1.2</title>
		<link>http://stereointeractive.com/blog/2009/01/23/uploading-a-file-with-symfony-12/</link>
		<comments>http://stereointeractive.com/blog/2009/01/23/uploading-a-file-with-symfony-12/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 21:42:12 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Propel]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=137</guid>
		<description><![CDATA[This post explains how to use the symfony 1.2 forms framework to handle a file upload. ]]></description>
			<content:encoded><![CDATA[<p>There is a post hidden within the symfony documentation that discusses how to upload a file using the new forms framework within symfony 1.2. If you are curious about the best way to handle file uploads, it&#8217;s worth reading this <a href="http://www.symfony-project.org/tutorial/1_2/whats-new#Forms">What&#8217;s New in Symfony 1.2</a> post first, and then come back here for a quick summary of how this works.</p>
<p>Let&#8217;s say you would like to allow users to upload PDF files to your site. You store data related to these file uploads in an &#8220;article&#8221; table in your database. This table has a column named &#8220;file&#8221; that stores the file name of the uploaded pdf.</p>
<p>The symfony forms framework will generate the basic (and not so basic) code to get you started. If you haven&#8217;t yet generated your form classes yet, you can do so with the command:</p>
<p><span id="more-137"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span class="sy0">/</span>symfony propel:build-forms</pre></div></div>

<p>Now navigate to lib/form/ArticleForm.class.php. To convert the file column to a file input field, we do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span class="kw2">class</span> ArtistResumeForm <span class="kw2">extends</span> BaseArtistResumeForm
<span class="br0">&#123;</span>
  <span class="kw2">public</span> <span class="kw2">function</span> configure<span class="br0">&#40;</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">widgetSchema</span><span class="br0">&#91;</span><span class="st_h">'file'</span><span class="br0">&#93;</span>        <span class="sy0">=</span> <span class="kw2">new</span> sfWidgetFormInputFile<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">validatorSchema</span><span class="br0">&#91;</span><span class="st_h">'file'</span><span class="br0">&#93;</span>     <span class="sy0">=</span> <span class="kw2">new</span> sfValidatorFile<span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'path'</span> <span class="sy0">=&gt;</span> sfConfig<span class="sy0">::</span><span class="me2">get</span><span class="br0">&#40;</span><span class="st_h">'sf_upload_dir'</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st_h">'/articles'</span><span class="sy0">,</span> <span class="st_h">'required'</span> <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Now, whenever you call $form->save(), your files will automatically be uploaded to the server, and the field &#8220;file&#8221; in your propel object will be updated with the new file name so you can easily retrieve it later. </p>
<p>If you are interested in getting this to work with embedded forms, check out this other post on <a href="http://stereointeractive.com/blog/2008/12/23/symfony-12-upload-a-file-inside-an-embedded-form/">uploading files within embedded forms with symfony 1.2</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/01/23/uploading-a-file-with-symfony-12/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
