<?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 - Ann Arbor, Michigan Web Design &#187; Symfony</title>
	<atom:link href="http://stereointeractive.com/blog/tag/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereointeractive.com/blog</link>
	<description>Development Blog</description>
	<lastBuildDate>Fri, 04 Nov 2011 03:46:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Symfony 1.4 admin generator sort on custom column</title>
		<link>http://stereointeractive.com/blog/2011/01/08/symfony-1-4-admin-generator-sort-on-custom-column/</link>
		<comments>http://stereointeractive.com/blog/2011/01/08/symfony-1-4-admin-generator-sort-on-custom-column/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 20:01:05 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=569</guid>
		<description><![CDATA[If you use the symfony 1.4 admin generator with doctrine you may notice that the column headings in the list view are links that enable you to sort your results by that column. If you customize the list view to include columns that include data from a foreign table, the generator will not automatically create [...]]]></description>
			<content:encoded><![CDATA[<p>If you use the symfony 1.4 admin generator with doctrine you may notice that the column headings in the list view are links that enable you to sort your results by that column. If you customize the list view to include columns that include data from a foreign table, the generator will not automatically create these sort links. Here is how I make foreign columns sortable. <span id="more-569"></span></p>
<p>Let&#8217;s say I have a model &#8220;Payment&#8221; and it has a one-to-many relationship with &#8220;Person&#8221; (i.e. one person has many payments, or the payment table has a foreign key &#8220;person_id&#8221;). I want the list of payments sortable by &#8220;last_name&#8221;.</p>
<p>In generator.yml:</p>

<div class="wp_syntax"><div class="code"><pre class="yml"> config:
  fields:
   last_name: { is_real: true }
...
  list:
    display:  [id, date, amount, last_name]</pre></div></div>

<p>Let&#8217;s update our Payment.class.php file with methods to fetch the person&#8217;s last name.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> Payment <span class="kw2">extends</span> BasePayment
<span class="br0">&#123;</span>
<span class="sy0">...</span>
  <span class="kw2">public</span> <span class="kw2">function</span> getLastName<span class="br0">&#40;</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">Person</span><span class="sy0">-&gt;</span><span class="me1">last_name</span><span class="sy0">;</span>
  <span class="br0">&#125;</span></pre></div></div>

<p>Now, if you reload your generated list view, you&#8217;ll see the column heading for last_name has been converted to a link. Now, we&#8217;ll have to add this foreign column (last_name) to our query and also add some logic to sort by the proper column when necessary.</p>
<p>Let&#8217;s add a custom table method to our list query, adding another line to generator.yml:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml">...
config:
  list:
  ...
    table_method: doSelectJoinPerson</pre></div></div>

<p>Let&#8217;s add the new method to our PaymentTable.class.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> PaymentTable <span class="kw2">extends</span> Doctrine_Table
<span class="br0">&#123;</span>
  <span class="sy0">...</span>  
  <span class="kw2">public</span> static <span class="kw2">function</span> doSelectJoinPerson<span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="re0">$rootAlias</span> <span class="sy0">=</span> <span class="re0">$query</span><span class="sy0">-&gt;</span><span class="me1">getRootAlias</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="kw1">return</span> <span class="re0">$query</span><span class="sy0">-&gt;</span><span class="me1">select</span><span class="br0">&#40;</span><span class="re0">$rootAlias</span> <span class="sy0">.</span> <span class="st_h">'.*, p.last_name'</span><span class="br0">&#41;</span>
      <span class="sy0">-&gt;</span><span class="me1">leftJoin</span><span class="br0">&#40;</span><span class="re0">$rootAlias</span> <span class="sy0">.</span> <span class="st_h">'.Person p'</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>The table_method parameter in our list configuration is used to define which method should be executed on our model&#8217;s table when it fetches results from the database.  Our main model will always have an alias &#8220;r&#8221; as defined in the symfony/doctrine source code (check out <code>sfFormFilterDoctrine::doBuildQuery()</code>). </p>
<p>We now need to pass the table alias for our foreign table (in this case, we used &#8216;p&#8217; for Person) into our sort query if &#8216;last_name&#8217; is given as our sort parameter. Let&#8217;s override the <code>addSortQuery($query)</code> in our actions class:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> paymentActions <span class="kw2">extends</span> autoPaymentActions
<span class="br0">&#123;</span>
<span class="sy0">...</span>
  <span class="kw2">protected</span> <span class="kw2">function</span> addSortQuery<span class="br0">&#40;</span><span class="re0">$query</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#40;</span><span class="kw4">null</span><span class="sy0">,</span> <span class="kw4">null</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="br0">&#40;</span><span class="re0">$sort</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">getSort</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
      <span class="kw1">return</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">in_array</span><span class="br0">&#40;</span><span class="kw3">strtolower</span><span class="br0">&#40;</span><span class="re0">$sort</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'asc'</span><span class="sy0">,</span> <span class="st_h">'desc'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
      <span class="re0">$sort</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'asc'</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">switch</span> <span class="br0">&#40;</span><span class="re0">$sort</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="kw1">case</span> <span class="st_h">'last_name'</span><span class="sy0">:</span>
        <span class="re0">$sort</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'p.last_name'</span><span class="sy0">;</span>
        <span class="kw1">break</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="re0">$query</span><span class="sy0">-&gt;</span><span class="me1">addOrderBy</span><span class="br0">&#40;</span><span class="re0">$sort</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="sy0">.</span> <span class="st_h">' '</span> <span class="sy0">.</span> <span class="re0">$sort</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="sy0">...</span></pre></div></div>

<p><strong>Update:</strong>A few comments below pointed out for the default admin generator theme you&#8217;ll also need to add the following method to your controller (actions.class.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">protected</span> <span class="kw2">function</span> isValidSortColumn<span class="br0">&#40;</span><span class="re0">$column</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
  <span class="kw1">return</span> Doctrine_Core<span class="sy0">::</span><span class="me2">getTable</span><span class="br0">&#40;</span>‘Payment’<span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">hasColumn</span><span class="br0">&#40;</span><span class="re0">$column</span><span class="br0">&#41;</span> <span class="sy0">||</span> <span class="re0">$column</span> <span class="sy0">==</span> ‘last_name’<span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Once you get used to this process, it&#8217;s really not too hard to implement for all of your admin-generated modules. No plugins necessary. </p>
<p><strong>Update 2:</strong> Updated doSelect query to use root alias defined in the query per the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2011/01/08/symfony-1-4-admin-generator-sort-on-custom-column/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>symfony forms: hide created_at, updated_at columns</title>
		<link>http://stereointeractive.com/blog/2010/04/07/symfony-forms-hide-created_at-updated_at-columns/</link>
		<comments>http://stereointeractive.com/blog/2010/04/07/symfony-forms-hide-created_at-updated_at-columns/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 22:40:53 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=504</guid>
		<description><![CDATA[There are a few different methods you can use if you&#8217;d like to hide created_at and updated_at columns from your generated forms. The first way, and the easiest, is to simply unset the fields in your form class: class SampleForm extends BaseSampleForm &#123; public function configure&#40;&#41; &#123; unset&#40; $this&#91;'created_at'&#93;, $this&#91;'updated_at'&#93; &#41;; &#125; &#125; If you [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few different methods you can use if you&#8217;d like to hide created_at and updated_at columns from your generated forms.</p>
<p>The first way, and the easiest, is to simply unset the fields in your form class:<br />
<span id="more-504"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> SampleForm <span class="kw2">extends</span> BaseSampleForm
<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="kw3">unset</span><span class="br0">&#40;</span>
      <span class="re0">$this</span><span class="br0">&#91;</span><span class="st_h">'created_at'</span><span class="br0">&#93;</span><span class="sy0">,</span>
      <span class="re0">$this</span><span class="br0">&#91;</span><span class="st_h">'updated_at'</span><span class="br0">&#93;</span>
    <span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>If you want the values to display in your form as read-only:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> SampleForm <span class="kw2">extends</span> BaseSampleForm
<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">'created_at'</span><span class="br0">&#93;</span>    <span class="sy0">=</span> <span class="kw2">new</span> sfWidgetFormInput<span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'readonly'</span><span class="sy0">=&gt;</span><span class="st_h">'readonly'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</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">'updated_at'</span><span class="br0">&#93;</span>    <span class="sy0">=</span> <span class="kw2">new</span> sfWidgetFormInput<span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="st_h">'readonly'</span><span class="sy0">=&gt;</span><span class="st_h">'readonly'</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>

]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/04/07/symfony-forms-hide-created_at-updated_at-columns/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony 1.2 doctrine file upload in form</title>
		<link>http://stereointeractive.com/blog/2010/03/30/symfony-1-2-doctrine-file-upload-in-form/</link>
		<comments>http://stereointeractive.com/blog/2010/03/30/symfony-1-2-doctrine-file-upload-in-form/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 00:06:51 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=497</guid>
		<description><![CDATA[Here are the required modifications for to a form class that contains a file upload field in symfony 1.2 using doctrine (and it probably works with propel, too). class NewsletterForm extends BaseNewsletterForm &#123; public function configure&#40;&#41; &#123; $this-&#62;widgetSchema&#91;'file'&#93; = new sfWidgetFormInputFileEditable&#40;array&#40; 'file_src' =&#62; '/uploads/'.$this-&#62;getObject&#40;&#41;-&#62;getfile&#40;&#41;, 'is_image' =&#62; true, 'edit_mode' =&#62; !$this-&#62;isNew&#40;&#41;, //'template' =&#62; '&#60;div&#62;%file%&#60;br /&#62;%input%&#60;br /&#62;%delete% [...]]]></description>
			<content:encoded><![CDATA[<p>Here are the required modifications for to a form class that contains a file upload field in symfony 1.2 using doctrine (and it probably works with propel, too).<br />
<span id="more-497"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> NewsletterForm <span class="kw2">extends</span> BaseNewsletterForm
<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> sfWidgetFormInputFileEditable<span class="br0">&#40;</span><span class="kw3">array</span><span class="br0">&#40;</span>
      <span class="st_h">'file_src'</span> <span class="sy0">=&gt;</span> <span class="st_h">'/uploads/'</span><span class="sy0">.</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">getObject</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">getfile</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
      <span class="st_h">'is_image'</span>  <span class="sy0">=&gt;</span> <span class="kw4">true</span><span class="sy0">,</span>
      <span class="st_h">'edit_mode'</span> <span class="sy0">=&gt;</span> <span class="sy0">!</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">isNew</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span>
      <span class="co1">//'template'  =&gt; '&lt;div&gt;%file%&lt;br /&gt;%input%&lt;br /&gt;%delete% %delete_label%&lt;/div&gt;',</span>
    <span class="br0">&#41;</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">'required'</span> <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="sy0">,</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="br0">&#41;</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_delete'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">new</span> sfValidatorPass<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>If you want to override the file name generated for your uploaded file, add a &#8216;generateXXXFileName()&#8217; method to your model&#8217;s class where XXX is the column name that contains the file name (in this example, our column is &#8220;file&#8221;, so the method name is &#8216;generateFileFilename&#8217;. It takes a single parameter, which is an instance of sfValidatedFile.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> Newsletter <span class="kw2">extends</span> BaseNewsletter
<span class="br0">&#123;</span>
  <span class="kw2">public</span> <span class="kw2">function</span> generateFileFileName<span class="br0">&#40;</span><span class="re0">$file</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="kw1">return</span> <span class="re0">$file</span><span class="sy0">-&gt;</span><span class="me1">getOriginalName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/03/30/symfony-1-2-doctrine-file-upload-in-form/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>symfony sync command configuration (with symfony 1.0)</title>
		<link>http://stereointeractive.com/blog/2010/03/22/symfony-sync-command-configuration-with-symfony-1-0/</link>
		<comments>http://stereointeractive.com/blog/2010/03/22/symfony-sync-command-configuration-with-symfony-1-0/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 10:18:57 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=467</guid>
		<description><![CDATA[I recently discovered a quick way to edit the rsync parameters used when executing the symfony sync command with symfony 1.0. I wanted to ignore timestamp and permissions differences, which wasn&#8217;t possible using the default configuration due to the -a (which stands for &#8216;archive&#8217; mode) parameter added to the rsync command. If you want to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered a quick way to edit the rsync parameters used when executing the <code>symfony sync</code> command with symfony 1.0. <span id="more-467"></span></p>
<p>I wanted to ignore timestamp and permissions differences, which wasn&#8217;t possible using the default configuration due to the -a (which stands for &#8216;archive&#8217; mode) parameter added to the rsync command. If you want to override the default settings, all you have to do is add a &#8216;parameters&#8217; key to your properties.ini file. Here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="php">  <span class="br0">&#91;</span>staging<span class="br0">&#93;</span>
    host<span class="sy0">=</span>yourhostname
    port<span class="sy0">=</span><span class="nu0">22</span>
    user<span class="sy0">=</span>yourusername
    <span class="kw3">dir</span><span class="sy0">=</span>your<span class="sy0">/</span>path<span class="sy0">/</span>to<span class="sy0">/</span>your<span class="sy0">/</span>app
    parameters<span class="sy0">=</span><span class="st_h">'-rlDzC --force --delete --exclude-from=config/rsync_exclude.txt'</span></pre></div></div>

<p>Keep in mind if you set your own custom parameters you won&#8217;t benefit from any of the default settings so you should include them yourself (like &#8211;force, &#8211;delete, and your rsycn_exclude file).</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/03/22/symfony-sync-command-configuration-with-symfony-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony 1.0 migrations</title>
		<link>http://stereointeractive.com/blog/2010/02/23/symfony-1-0-migrations/</link>
		<comments>http://stereointeractive.com/blog/2010/02/23/symfony-1-0-migrations/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 14:11:30 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=431</guid>
		<description><![CDATA[I&#8217;m working on a plugin for symfony 1.0 and am really enjoying this workflow. Yes, symfony 1.0 is 4 versions old and should not be used for new projects. With the help of the sfPropelMigrationsLightPlugin plugin, one of my favorites, I have been rapidly making changes to my plugin schema and adding new data to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a plugin for symfony 1.0 and am really enjoying this workflow. Yes, symfony 1.0 is 4 versions old and should not be used for new projects. </p>
<p>With the help of the <a href='http://www.symfony-project.org/plugins/sfPropelMigrationsLightPlugin'>sfPropelMigrationsLightPlugin</a> plugin, one of my favorites, I have been rapidly making changes to my plugin schema and adding new data to the database over and over again while I mock things up.</p>
<p>Here is the workflow:<br />
<span id="more-431"></span><br />
1. make changes to the plugin&#8217;s schema.yml file, in plugins/myPlugin/config/schema.yml<br />
2. make changes to the plugin&#8217;s fixtures file, in plugins/myPlugin/data/fixtures/fixtures.yml<br />
3. rebuild the model<br />
4. rebuild the sql<br />
5. copy the plugin&#8217;s sql to the migration sql source file<br />
6. run the migration<br />
7. load the fixtures</p>
<p>This gives me my new schema and populates it with whatever data I have in the fixtures.</p>
<p>Optionally, if I want to go back and make another change, I migrate down a version first, then run through the process above.</p>
<p>The trick is to make your migration run an external SQL file, and to use the plugin&#8217;s generated SQL as the source for that migration.</p>
<p>Here is my migration (remember this uses the sfMigrationsLightPlugin):</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">&lt;?php</span>
&nbsp;
<span class="co4">/**
 * Migrations between versions 033 and 034.
 */</span>
<span class="kw2">class</span> Migration034 <span class="kw2">extends</span> sfMigration
<span class="br0">&#123;</span>
  <span class="co4">/**
   * Migrate up to version 034.
   */</span>
  <span class="kw2">public</span> <span class="kw2">function</span> up<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">loadSql</span><span class="br0">&#40;</span><span class="kw3">dirname</span><span class="br0">&#40;</span><span class="kw4">__FILE__</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st_h">'/034_stDataflow.sql'</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&nbsp;
  <span class="co4">/**
   * Migrate down to version 033.
   */</span>
  <span class="kw2">public</span> <span class="kw2">function</span> down<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">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;SET FOREIGN_KEY_CHECKS = 0;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;DROP TABLE IF EXISTS `dataflow_import_map`;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;DROP TABLE IF EXISTS `dataflow_profile_history`;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;DROP TABLE IF EXISTS `dataflow_batch_import`;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;DROP TABLE IF EXISTS `dataflow_batch`;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;DROP TABLE IF EXISTS `dataflow_profile`;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">executeSQL</span><span class="br0">&#40;</span><span class="st0">&quot;SET FOREIGN_KEY_CHECKS = 1;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

<p>Here&#8217;s how I run it, once I have completed my new schema.yml and fixtures.yml changes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span class="co0"># if this is not the first time I'm going through this process, </span>
<span class="co0"># I need to migrate back a step to remove my old plugin tables</span>
.<span class="sy0">/</span>symfony migrate myapp:dev <span class="nu0">33</span>  <span class="co0">#33 is my previous migration number</span>
<span class="sy0">&gt;&gt;</span> migrations migrated <span class="nu0">1</span> step<span class="br0">&#40;</span>s<span class="br0">&#41;</span>
<span class="sy0">&gt;&gt;</span> migrations current database version: <span class="nu0">33</span>
$ .<span class="sy0">/</span>symfony propel-build-model
<span class="kw2">cp</span> data<span class="sy0">/</span>sql<span class="sy0">/</span>plugins.stDataflowPlugin.lib.model.schema.sql data<span class="sy0">/</span>migrations<span class="sy0">/</span>034_stDataflow.sql
.<span class="sy0">/</span>symfony migrate npas:dev <span class="nu0">34</span>
<span class="sy0">&gt;&gt;</span> migrations migrated <span class="nu0">1</span> step<span class="br0">&#40;</span>s<span class="br0">&#41;</span>
<span class="sy0">&gt;&gt;</span> migrations current database version: <span class="nu0">34</span>
.<span class="sy0">/</span>symfony propel-load-data npas dev plugins<span class="sy0">/</span>stDataflowPlugin<span class="sy0">/</span>data<span class="sy0">/</span>fixtures<span class="sy0">/</span>fixtures.yml
<span class="sy0">&gt;&gt;</span> propel    load data from <span class="st0">&quot;plugins/stDataf...gin/data/fixtures/fixtures.yml&quot;</span></pre></div></div>

<p>It&#8217;s nothing novel, but a good example of using the tools to improve the workflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/02/23/symfony-1-0-migrations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symfony Resource Reference Guide</title>
		<link>http://stereointeractive.com/blog/2010/02/21/symfony-resource-reference-guide/</link>
		<comments>http://stereointeractive.com/blog/2010/02/21/symfony-resource-reference-guide/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 21:54:28 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=415</guid>
		<description><![CDATA[Symfony has a ton of documentation available online. The only problem is, with so many different versions (1.0 &#8211; 1.4) in the wild, it can be hard to locate exactly the right resource when you need it. Below is a simple and straightforward list of the most useful documentation: Jump to the By Format or [...]]]></description>
			<content:encoded><![CDATA[<p>Symfony has a ton of documentation available online. The only problem is, with so many different versions (1.0 &#8211; 1.4) in the wild, it can be hard to locate exactly the right resource when you need it. Below is a simple and straightforward list of the most useful documentation:</p>
<p><span id="more-415"></span></p>
<p>Jump to the <a href="#format">By Format</a> or <a href="#version">By Version</a>.</p>
<p><strong>By Format:</strong><a name="format"></a></p>
<ul>
<li>Getting Started:
<ul>
<li><a href="http://www.symfony-project.org/getting-started/1_4/en/">Getting Started (1.4)</a></li>
<li><a href="http://www.symfony-project.org/getting-started/1_2/en/">Getting Started (1.2)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_2/en/my-first-project">My First Project (1.2)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_0/en/my-first-project">My First Project (1.0)</a></li>
</ul>
</li>
<li>Tutorials (Jobeet / Askeet / Cookbook)
<ul>
<li><a href="http://www.symfony-project.org/jobeet/1_4/Propel/en/">Jobeet (1.4, Propel)</a></li>
<li><a href="http://www.symfony-project.org/jobeet/1_4/Doctrine/en/">Jobeet (1.4, Doctrine)</a></li>
<li><a href="http://www.symfony-project.org/jobeet/1_2/Propel/en/">Jobeet (1.2, Propel)</a></li>
<li><a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/ ">Jobeet (1.2, Doctrine)</a></li>
<li><a href="http://www.symfony-project.org/askeet/1_0/en/">Askeet (1.0)</a></li>
<li><a href="http://www.symfony-project.org/more-with-symfony/1_4/en/">More with symfony / advanced tutorials (1.4)</a></li>
<li><a href="http://www.symfony-project.org/cookbook/1_2/en/">Cookbook (1.2)</a></li>
<li><a href="http://www.symfony-project.org/cookbook/1_0/en/">Cookbook (1.0)</a></li>
</ul>
</li>
<li>&#8220;The Book&#8221;:
<ul>
<li><a href="http://www.symfony-project.org/book/1_2/">The Definitive Guide to symfony (1.2)</a></li>
<li><a href="http://www.symfony-project.org/book/1_0/">The Definitive Guide to symfony (1.0)</a></li>
</ul>
</li>
<li>Reference Guide (configuration, events, tasks):
<ul>
<li><a href="http://www.symfony-project.org/reference/1_4/en/">symfony Reference Guide (1.4)</a></li>
<li><a href="http://www.symfony-project.org/reference/1_2/en/">symfony Reference Guide (1.2)</a></li>
</ul>
</li>
<li>Admin Generator:
<ul>
<li><a href="http://www.symfony-project.org/book/1_2/14-Generators#Administration">Admin Generator (1.2)</a></li>
<li><a href="http://www.symfony-project.org/book/1_0/14-Generators#Administration">Admin Generator (1.0)</a></li>
</ul>
</li>
<li>Forms:
<ul>
<li><a href="http://www.symfony-project.org/forms/1_4/en/">symfony Forms in Action</a></li>
<li><a href="http://www.symfony-project.org/forms/1_2/en/">symfony Forms (1.2)</a></li>
</ul>
</li>
<li>API:
<ul>
<li><a href="http://www.symfony-project.org/api/1_4/">API (1.4)</a></li>
<li><a href="http://www.symfony-project.org/api/1_2/">API (1.2)</a></li>
<li><a href="http://www.symfony-project.org/api/1_0/">API (1.0)</a></li>
</ul>
</li>
<li>Installing/Upgrading:
<ul>
<li><a href="http://www.symfony-project.org/tutorial/1_4/en/upgrade">Upgrade (1.4)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_2/upgrade">Upgrade (1.2)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_4">Installation (1.4)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_2">Installation (1.2)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_0">Installation (1.0)</a></li>
</ul>
</li>
<li>What&#8217;s New:
<ul>
<li><a href="http://www.symfony-project.org/tutorial/1_4/en/upgrade">What&#8217;s New (1.4)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_2/en/whats-new">What&#8217;s New (1.2)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_4/en/deprecated">Deprecated (1.4)</a></li>
</ul>
</li>
</ul>
<p><strong>By Version:</strong><a name="version"></a></p>
<ul>
<li>Symfony 1.3/1.4
<ul>
<li><a href="http://www.symfony-project.org/getting-started/1_4/en/">Getting Started (1.4)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_4/en/whats-new">What&#8217;s New (1.4)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_4/en/upgrade">Upgrade (1.4)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_4/en/deprecated">Deprecated (1.4)</a></li>
<li><a href="http://www.symfony-project.org/jobeet/1_4/Doctrine/en/">Jobeet (1.4, Propel)</a></li>
<li><a href="http://www.symfony-project.org/jobeet/1_4/Propel/en/">Jobeet (1.4, Doctrine)</a></li>
<li><a href="http://www.symfony-project.org/reference/1_4/en/">symfony Reference Guide (1.4)</a></li>
<li><a href="http://www.symfony-project.org/more-with-symfony/1_4/en/">More with symfony / advanced tutorials (1.4)</a></li>
<li><a href="http://www.symfony-project.org/api/1_4/">API (1.4)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_4">Installation (1.4)</a></li>
</ul>
</li>
<li>Symfony 1.2
<ul>
<li><a href="http://www.symfony-project.org/jobeet/1_2/Propel/en/">Jobeet (1.2, Propel)</a></li>
<li><a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/ ">Jobeet (1.2, Doctrine)</a></li>
<li><a href="http://www.symfony-project.org/reference/1_2/en/">symfony Reference Guide (1.2)</a></li>
<li><a href="http://www.symfony-project.org/book/1_2/">The Definitive Guide to symfony (1.2)</a></li>
<li><a href="http://www.symfony-project.org/forms/1_2/en/">symfony Forms (1.2)</a></li>
<li><a href="http://www.symfony-project.org/cookbook/1_2/en/">Cookbook (1.2)</a></li>
<li><a href="http://www.symfony-project.org/api/1_2/">API (1.2)</a></li>
<li><a href="http://www.symfony-project.org/getting-started/1_2/en/">Getting Started (1.2)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_2/en/whats-new">What&#8217;s New (1.2)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_2/en/my-first-project">My First Project (1.2)</a></li>
<li><a href="http://www.symfony-project.org/book/1_2/14-Generators#Administration">Admin Generator (1.2)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_2">Installation (1.2)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_2/upgrade">Upgrade (1.2)</a></li>
</ul>
</li>
<li>Symfony 1.0
<ul>
<li><a href="http://www.symfony-project.org/book/1_0/">The Definitive Guide to symfony (1.0)</a></li>
<li><a href="http://www.symfony-project.org/cookbook/1_0/en/">Cookbook (1.0)</a></li>
<li><a href="http://www.symfony-project.org/api/1_0/">API (1.0)</a></li>
<li><a href="http://www.symfony-project.org/tutorial/1_0/en/my-first-project">My First Project (1.0)</a></li>
<li><a href="http://www.symfony-project.org/askeet/1_0/en/">Askeet (1.0)</a></li>
<li><a href="http://www.symfony-project.org/cookbook/1_0/en/">Cookbook (1.0)</a></li>
<li><a href="http://www.symfony-project.org/book/1_0/14-Generators#Administration">Admin Generator (1.0)</a></li>
<li><a href="http://www.symfony-project.org/installation/1_0">Installation (1.0)</a></li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/02/21/symfony-resource-reference-guide/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Symfony Experts</title>
		<link>http://stereointeractive.com/blog/2010/02/21/symfony-experts/</link>
		<comments>http://stereointeractive.com/blog/2010/02/21/symfony-experts/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 20:37:46 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=409</guid>
		<description><![CDATA[Two good friends of mine just launched a new site dedicated to providing professional help to symfony developers. Symfony Experts. The site is very well designed and will prove to be a valuable resource for developers of all skill levels — experts can make some extra money sharing their expertise, and beginners (or experts encountering [...]]]></description>
			<content:encoded><![CDATA[<p>Two good friends of mine just launched a new site dedicated to providing professional help to symfony developers.</p>
<p><a href='http://www.symfonyexperts.com/'>Symfony Experts</a>.</p>
<p>The site is very well designed and will prove to be a valuable resource for developers of all skill levels — experts can make some extra money sharing their expertise, and beginners (or experts encountering a new problem) can get quick and succinct answers to their questions.<br />
<span id="more-409"></span></p>
<p>From the about page:</p>
<blockquote><p>
Symfony Experts is problem-solving community for Symfony, ideal for users seeking quick, succinct answers they can&#8217;t find in any Symfony forums. Symfony Experts is also great for established Symfony developers who want to help problem-solve and be paid fairly for their efforts.
</p></blockquote>
<p>I highly recommend it. </p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2010/02/21/symfony-experts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#8220;Could not create database for c&#8230;o use near&#8221; error with Doctrine / Symfony</title>
		<link>http://stereointeractive.com/blog/2009/12/31/could-not-create-database-for-c-o-use-near-error-with-doctrine-symfony/</link>
		<comments>http://stereointeractive.com/blog/2009/12/31/could-not-create-database-for-c-o-use-near-error-with-doctrine-symfony/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 22:44:40 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=386</guid>
		<description><![CDATA[I was trying to use the symfony command line tools to rebuild my test database and I couldn&#8217;t get past this error: &#62;&#62; doctrine Could not create database for c...o use near '-sb-test' at line 1 Turns out the issue is with the &#8220;-&#8221; in my test database name. Replacing the hyphens with underscores fixed [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to use the symfony command line tools to rebuild my test database and I couldn&#8217;t get past this error:<span id="more-386"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span class="sy0">&gt;&gt;</span> doctrine Could not create database <span class="kw1">for</span> c...o use near <span class="st_h">'-sb-test'</span> at line <span class="nu0">1</span></pre></div></div>

<p>Turns out the issue is with the &#8220;-&#8221; in my test database name. Replacing the hyphens with underscores fixed the problem. </p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/12/31/could-not-create-database-for-c-o-use-near-error-with-doctrine-symfony/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Symfony, Doctrine Upload File &#8220;validation failed&#8221;</title>
		<link>http://stereointeractive.com/blog/2009/10/04/symfony-doctrine-upload-file-validation-failed/</link>
		<comments>http://stereointeractive.com/blog/2009/10/04/symfony-doctrine-upload-file-validation-failed/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 05:19:49 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=335</guid>
		<description><![CDATA[After setting up a simple file upload using the symfony 1.2 forms class and a doctrine model, I hit this error right away: 500 &#124; Internal Server Error &#124; Doctrine_Validator_Exception 1 field had validation error: * 1 validator failed on file &#40;type&#41; The short solution: when using a doctrine form class and $form->save(), set the [...]]]></description>
			<content:encoded><![CDATA[<p>After setting up a simple file upload using the symfony 1.2 forms class and a doctrine model, I hit this error right away:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span class="nu0">500</span> <span class="sy0">|</span> Internal Server Error <span class="sy0">|</span> Doctrine_Validator_Exception
 <span class="nu0">1</span> field had validation error:
 <span class="sy0">*</span> <span class="nu0">1</span> validator failed on <span class="kw2">file</span> <span class="br0">&#40;</span><span class="kw3">type</span><span class="br0">&#41;</span></pre></div></div>

<p><strong>The short solution: when using a doctrine form class and $form->save(), set the path option in your sfValidatorFile validator and do not attempt to save/set the file column yourself.</strong> If you are curious why this is, continue reading.<span id="more-335"></span></p>
<p>What was particularly strange about this error is that the &#8220;file&#8221; column in my model was defined as a string, and I was certain I was setting this column by hand to the file name (a string) of the uploaded file. Hmm&#8230; this shouldn&#8217;t trigger an error, should it? This following is what <strong>did not work</strong>. I used the documentation for sfValidatorFile() found in the<a href="http://www.symfony-project.org/forms/1_2/en/02-Form-Validation#chapter_02_file_upload"> symfony Forms book</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="co1">// my form</span>
<span class="kw2">class</span> ArtistForm <span class="kw2">extends</span> BaseArtistForm
<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>
    <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">'required'</span> <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="sy0">,</span> <span class="st_h">'mime_types'</span> <span class="sy0">=&gt;</span> <span class="st_h">'web_images'</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>
&nbsp;
<span class="co1">// my action ***did not work***</span>
<span class="kw2">public</span> <span class="kw2">function</span> executeForm<span class="br0">&#40;</span>sfWebRequest <span class="re0">$request</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span> <span class="sy0">=</span> <span class="kw2">new</span> ArtistForm<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$request</span><span class="sy0">-&gt;</span><span class="me1">isMethod</span><span class="br0">&#40;</span><span class="st_h">'post'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">bind</span><span class="br0">&#40;</span><span class="re0">$request</span><span class="sy0">-&gt;</span><span class="me1">getParameter</span><span class="br0">&#40;</span><span class="st_h">'artist'</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="re0">$request</span><span class="sy0">-&gt;</span><span class="me1">getFiles</span><span class="br0">&#40;</span><span class="st_h">'artist'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">isValid</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
      <span class="br0">&#123;</span>
        <span class="re0">$file</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">getValue</span><span class="br0">&#40;</span><span class="st_h">'file'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$file</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
          <span class="re0">$filename</span> <span class="sy0">=</span> <span class="kw3">sha1</span><span class="br0">&#40;</span><span class="re0">$file</span><span class="sy0">-&gt;</span><span class="me1">getOriginalName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
          <span class="re0">$extension</span> <span class="sy0">=</span> <span class="re0">$file</span><span class="sy0">-&gt;</span><span class="me1">getExtension</span><span class="br0">&#40;</span><span class="re0">$file</span><span class="sy0">-&gt;</span><span class="me1">getOriginalExtension</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
          <span class="re0">$file</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</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">'/'</span><span class="sy0">.</span><span class="re0">$filename</span><span class="sy0">.</span><span class="re0">$extension</span><span class="br0">&#41;</span><span class="sy0">;</span>          
          <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">getObject</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">setFile</span><span class="br0">&#40;</span><span class="re0">$filename</span><span class="sy0">.</span><span class="re0">$extension</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>    
  <span class="br0">&#125;</span></pre></div></div>

<p>Anytime I&#8217;d try to upload a file, I&#8217;d get the dreaded &#8220;Doctrine_Validator_Exception&#8221;, &#8220;validator failed on file (type)&#8221; message. After some serious googling, I came up with a few links (listed at the bottom of this post) that eventually led me to the solution. The issues boils down to this:</p>
<ul>
<li>When using the sfValidatorFile widget in your form, retrieving that value from your form returns an sfValidatedFile object</li>
<li>Doctrine forms will automatically try to process and save uploaded files, so you do not need to do this manually in your action if you call $form->save() and your form contains an instance of sfValidatorFile</li>
<li>The automatic save mechanism in your doctrine form <strong>will fail</strong> if you do not define a path in your sfValidatorFile validator. This is because if no path is defined in your validator, <strong>the validator returns an instance of sfValidatedFile</strong> and calling $form->save() will result in trying to update your doctrine object with this sfValidatorFile instance, resulting in an error.</li>
<li>If a path is defined in your sfValidatorFile validator, the bound form value for your file input field is set to the full path to saved file rather than an sfValidatedFile instance, allowing your doctrine object to be saved.</li>
</ul>
<p>Now, with a deeper understanding of how this is all put together, we can update our action:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span class="co1">// doctrine form class</span>
<span class="kw2">class</span> ArtistForm <span class="kw2">extends</span> BaseArtistForm
<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">'photo'</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>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">validatorSchema</span><span class="br0">&#91;</span><span class="st_h">'photo'</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">'required'</span> <span class="sy0">=&gt;</span> <span class="kw4">false</span><span class="sy0">,</span> <span class="st_h">'mime_types'</span> <span class="sy0">=&gt;</span> <span class="st_h">'web_images'</span><span class="sy0">,</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="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co1">// the action</span>
  <span class="kw2">public</span> <span class="kw2">function</span> executeForm<span class="br0">&#40;</span>sfWebRequest <span class="re0">$request</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span> <span class="sy0">=</span> <span class="kw2">new</span> ArtistForm<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$request</span><span class="sy0">-&gt;</span><span class="me1">isMethod</span><span class="br0">&#40;</span><span class="st_h">'post'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
      <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">bind</span><span class="br0">&#40;</span><span class="re0">$request</span><span class="sy0">-&gt;</span><span class="me1">getParameter</span><span class="br0">&#40;</span><span class="st_h">'artist'</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="re0">$request</span><span class="sy0">-&gt;</span><span class="me1">getFiles</span><span class="br0">&#40;</span><span class="st_h">'artist'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">isValid</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
      <span class="br0">&#123;</span>
        <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">form</span><span class="sy0">-&gt;</span><span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>    
  <span class="br0">&#125;</span></pre></div></div>

<p>More about this issue in the forums and mailing list:</p>
<ul>
<li><a href="http://forum.symfony-project.org/index.php/m/74831/">http://forum.symfony-project.org/index.php/m/74831/</a></li>
<li><a href="http://groups.google.com/group/symfony-users/browse_thread/thread/668a44a52a775938/3d55c8bb40290dbe?show_docid=3d55c8bb40290dbe">http://groups.google.com/group/symfony-users/browse_thread/thread/668a44a52a775938/3d55c8bb40290dbe?show_docid=3d55c8bb40290dbe</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/10/04/symfony-doctrine-upload-file-validation-failed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Speedup: Profile your symfony app using Xdebug &#8211; Web Mozarts</title>
		<link>http://stereointeractive.com/blog/2009/08/24/speedup-profile-your-symfony-app-using-xdebug-web-mozarts/</link>
		<comments>http://stereointeractive.com/blog/2009/08/24/speedup-profile-your-symfony-app-using-xdebug-web-mozarts/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 16:28:10 +0000</pubDate>
		<dc:creator>Scott Meves</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=313</guid>
		<description><![CDATA[Speedup: Profile your symfony app using Xdebug &#8211; Web Mozarts. Haven&#8217;t tried this but hope to, soon!]]></description>
			<content:encoded><![CDATA[<p><a href='http://webmozarts.com/2009/05/01/speedup-performance-profiling-for-your-symfony-app/'>Speedup: Profile your symfony app using Xdebug &#8211; Web Mozarts</a>.</p>
<p>Haven&#8217;t tried this but hope to, soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://stereointeractive.com/blog/2009/08/24/speedup-profile-your-symfony-app-using-xdebug-web-mozarts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

