<?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>devexp &#187; Symfony</title>
	<atom:link href="http://www.devexp.eu/tag/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexp.eu</link>
	<description>DEVelopment EXPerience, shared with the world!</description>
	<lastBuildDate>Fri, 28 Oct 2011 12:07:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to use a symfony 1 layout from a different directory</title>
		<link>http://www.devexp.eu/2011/10/28/how-to-use-a-symfony-1-layout-from-a-different-directory/</link>
		<comments>http://www.devexp.eu/2011/10/28/how-to-use-a-symfony-1-layout-from-a-different-directory/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 11:48:36 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Layout]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=1042</guid>
		<description><![CDATA[In symfony 1 it is possible to have different layouts for an application. But they all have to be put into the directory &#8216;myproject/apps/frontend/templates/&#8217;. But what if you want to use a layout from another location? Assume you make a &#8230; <a href="http://www.devexp.eu/2011/10/28/how-to-use-a-symfony-1-layout-from-a-different-directory/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://www.devexp.eu/wp-content/uploads/2009/04/symfony.jpg"><img src="http://www.devexp.eu/wp-content/uploads/2009/04/symfony.jpg" alt="" title="Symfony" width="127" height="35" class="alignright size-full wp-image-727" /></a>In symfony 1 it is possible to have different layouts for an application. But they all have to be put into the directory &#8216;myproject/apps/frontend/templates/&#8217;. But what if you want to use a layout from another location? </p>
<p>Assume you make a plugin with a specific layout, it would be nice to load the layout from the plugin directory, and not to have to copy the file to the global directory.</p>
<p>Here is how you can achieve this:</p>
<pre class="brush: php; title: ; notranslate">
$template = $this-&gt;getContext()-&gt;getConfiguration()-&gt;getTemplateDir('MODULE', 'LAYOUT_FILE.php');
$this-&gt;setLayout($template . '/LAYOUT_FILE');
</pre>
<p>Let&#8217;s say you have the following:</p>
<pre class="brush: plain; title: ; notranslate">
my_project/
  plugins/
    my_plugin/
      modules/
        MyUser/
          actions/
            actions.php
          templates/
            indexSuccess.php
            MyUserLayout.php
</pre>
<p>The actions.php class could be something like this:</p>
<pre class="brush: php; title: ; notranslate">
class MyUserAction extends sfActions {

  public function preExecute() {
    $template = $this-&gt;getContext()-&gt;getConfiguration()-&gt;getTemplateDir('MyUser', 'MyUserLayout.php');

    $this-&gt;setLayout($template . '/MyUserLayout');
  }

  public function executeIndex() {

  }
}
</pre>
<p>Have fun!</p>
<div class="shr-publisher-1042"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2011/10/28/how-to-use-a-symfony-1-layout-from-a-different-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to force symfony colors on windows with PuttyCyg?</title>
		<link>http://www.devexp.eu/2009/09/22/how-to-force-symfony-colors-on-windows-with-cygwinputtycyg/</link>
		<comments>http://www.devexp.eu/2009/09/22/how-to-force-symfony-colors-on-windows-with-cygwinputtycyg/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 13:18:14 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=936</guid>
		<description><![CDATA[Those of you who’re developing with symfony under windows will have noticed that, when running tasks in the command prompt, no colors are used. This is because the windows command prompt isn’t compatible with the color notation. Most of you &#8230; <a href="http://www.devexp.eu/2009/09/22/how-to-force-symfony-colors-on-windows-with-cygwinputtycyg/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Those of you who’re developing with symfony under windows will have noticed that, when running tasks in the command prompt, no colors are used. This is because the windows command prompt isn’t compatible with the color notation.<br />
Most of you also have <a href="http://www.cygwin.com/">cygwin</a> installed (shame on you if you didn’t :p). But even if you run the tasks through “<a href="http://code.google.com/p/puttycyg/">PuttyCyg</a>”, which is fully compatible with the color notation, you will not benefit from the colors. </p>
<p>Why?</p>
<p><span id="more-936"></span><br />
The problem resides in the symfony class “sfAnsiColorFormatter” in the method “supportsColors($stream)”:</p>
<pre class="brush: php; title: ; notranslate">
  /**
   * Returns true if the stream supports colorization.
   *
   * Colorization is disabled if not supported by the stream:
   *
   *  -  windows
   *  -  non tty consoles
   *
   * @param mixed $stream A stream
   *
   * @return Boolean true if the stream supports colorization, false otherwise
   */
  public function supportsColors($stream)
  {
    return DIRECTORY_SEPARATOR != '\\' &amp;&amp; function_exists('posix_isatty') &amp;&amp; @posix_isatty($stream);
  }
</pre>
<p>The method supportsColors($stream) decides whether or not colors are supported. And as you can see, one of the checks is the directory separator which in our case will always return false because we are on a windows operating system. So even if you run tasks through puttycyg the directory separator will remain the same.</p>
<p><strong>Possibility 1</strong></p>
<p>If you always work through the puttycyg you could simply set the method to always return true, but in a command prompt it will look like this:<br />
<div id="attachment_946" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.devexp.eu/wp-content/uploads/2009/09/command_output.png"><img src="http://www.devexp.eu/wp-content/uploads/2009/09/command_output-300x236.png" alt="Dos Command Output" title="Dos Command Output" width="300" height="236" class="size-medium wp-image-946" /></a><p class="wp-caption-text">Dos Command Output</p></div></p>
<p><strong>Possibility 2</strong></p>
<p>Detect if cygwin is used. This way when you use the dos command the output will work and when cygwin is used you&#8217;ll have the colors <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>I checked the $_SERVER array to find something that could help me to distinguish the cygwin prompt with the dos prompt, and I found that the &#8216;PWD&#8217; key is only available on *nix shells. And when I print the value of $_SERVER['PWD'] in the cygwin prompt it gives me &#8220;/cygdrive/f/sandbox/adlogix/branch-3.2/frontend&#8221;. </p>
<p>Knowing that, here is how we can change the supportsColors method:</p>
<pre class="brush: php; title: ; notranslate">
  /**
   * Returns true if the stream supports colorization.
   *
   * Colorization is disabled if not supported by the stream:
   *
   *  -  windows
   *  -  non tty consoles
   *
   * @param mixed $stream A stream
   *
   * @return Boolean true if the stream supports colorization, false otherwise
   */
  public function supportsColors($stream)
  {
    $supported = DIRECTORY_SEPARATOR != '\\' &amp;&amp; function_exists('posix_isatty') &amp;&amp; @posix_isatty($stream);

    return $supported ? true : !is_bool(strpos(@$_SERVER['PWD'], &quot;/cygdrive&quot;));
  }
</pre>
<p>What I did, is still using the check symfony used, but when it returns false I do a second check to see if the $_SERVER['PWD'] exists and that it contains the String &#8220;/cygdrive&#8221;.</p>
<p>Now when I run the taks through cygwin I get the colors and when I run it in dos it displays correctly.<br />
<div id="attachment_950" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.devexp.eu/wp-content/uploads/2009/09/puttycyg-versus-dos.png"><img src="http://www.devexp.eu/wp-content/uploads/2009/09/puttycyg-versus-dos-300x187.png" alt="PuttyCyg versus Dos" title="PuttyCyg versus Dos" width="300" height="187" class="size-medium wp-image-950" /></a><p class="wp-caption-text">PuttyCyg versus Dos</p></div></p>
<p>I only tested it on my machine, so if you have troubles or a better way to do it, please let me know <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>Update:</strong> This is only tested with symfony 1.2 and as from sf 1.3 there will be an option &#8211;color to force the colors.</p>
<p><strong>Update:</strong> For some reason it does not work in the cygwin bash shell. When I set the message manually (echo -e &#8220;\033[31mHello World\033[0m&#8221;) in the command the colors appear, but through symfony not.  I suspect that the cygwin bash shell miss interprets the returns of php, but I have no idea why it does work on puttyCyg (which only launches the cygwin shell) &#8230; probably some startup configuration of the bash ?!</p>
<div class="shr-publisher-936"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/09/22/how-to-force-symfony-colors-on-windows-with-cygwinputtycyg/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Interview: Stefan Koopmanschap</title>
		<link>http://www.devexp.eu/2009/09/22/interview-stefan-koopmanschap/</link>
		<comments>http://www.devexp.eu/2009/09/22/interview-stefan-koopmanschap/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 06:24:18 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[Koopmanschap]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Stefan]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=928</guid>
		<description><![CDATA[A few weeks ago I thought it might be cool to get some interesting guys, which are occupied with projects in PHP, interviewed. And guess what, we got on contact with Mr. Stefan Koopmanschap and he was kind enough to &#8230; <a href="http://www.devexp.eu/2009/09/22/interview-stefan-koopmanschap/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignright size-full wp-image-977" style="border: 0pt none; margin: 5px;" title="3317597132_6be12c93c7" src="http://www.devexp.eu/wp-content/uploads/2009/09/3317597132_6be12c93c7.jpg" alt="3317597132_6be12c93c7" width="160" height="240" /></p>
<p>A few weeks ago I thought it might be cool to get some interesting guys, which are occupied with projects in PHP, interviewed. And guess what, we got on contact with Mr. Stefan Koopmanschap and he was kind enough to answer all our questions.</p>
<blockquote><p>Stefan Koopmanschap (&#8216;left&#8217;) is a PHP developer, consultant and trainer with an eye for best practices. He works at <a href="http://www.unet.nl/" target="_blank">Unet</a> as (symfony) developer and development team leader. He is a community person and is active in the european PHP community as secretary of the <a href="http://www.phpbenelux.eu/" target="_blank">phpBenelux</a> Usergroup as well as in the Symfony community by advocating symfony and as the Community Manager.</p>
<p>Stefan has a wide history in Open Source, having been Support Team Leader for phpBB, documentation translator for Zend Framework and community manager, plugin developer and maintainer plus various other things for symfony.</p>
<p>Stefan is also a best practices advocate. He prefers easy and useful explanations of best practices over the academic and theoretical stuff found in most literature.</p></blockquote>
<p>Hope you enjoy this interview!</p>
<p><strong>Hello Stefan, first of all, thx for taking the time to answer all our questions.</strong></p>
<p><strong>Can you tell us what projects you are currently working on?</strong></p>
<p>At work I am involved in a big project to build an application that will handle all the administration, provisioning and handling of user accounts etc. for the whole VOiP and connectivity of the services we offer. Aside from that, my main projects are being the Community Manager for symfony and also preparing some new talks for the upcoming conferences.</p>
<p><span id="more-928"></span></p>
<p><strong>What technologies will become important in your line of work in the<br />
near future?</strong></p>
<p>Obviously, a big part of my life is currently being ruled by Symfony. It is the framework we use at my work, and because of my involvement in the project it also rules a big part of my private time. Also, other frameworks (such as Zend Framework) take a part of my life for projects I&#8217;m working on. For one of my personal development projects I&#8217;m also looking into jobqueue/message servers such as <a href="http://www.dropr.org/" target="_blank">Dropr </a>and <a href="http://www.gearman.org/" target="_blank">Gearman</a>. And of course I&#8217;m always reading into new technologies to know what they can do, so I can apply that knowledge at a later date.</p>
<p><strong>How did you get the knowledge you master today? Where there seminars, lessons, people, self education or other ways important to become who you are today?</strong></p>
<p>I have no Computer Science background, most of my current knowledge is self-taught or I picked up through experience over the years. Sometimes this is a good thing but often this has been a problem since over the years I have reinvented the wheel. Reading about design patterns for instance I often found out the things I &#8220;invented&#8221; were really thought about way before me by much smarter people who also considered many more things that I had considered. But by reading about many of these topics and best practices, I&#8217;ve picked up quite a bit of knowledge over the years. Combine that with the variation of projects I&#8217;ve been involved in and you get the knowledge and experience I&#8217;ve picked up.</p>
<p><strong>Do you consider yourself a lucky guy or did you earn all your  success because of yourself?<br />
</strong><br />
A bit of both. I&#8217;ve obviously done a lot of work to get to the point where I am right now, yet I also consider myself a lucky guy. The amount of conferences I get accepted to speaking at these days allows me to travel around the world and meet the brightest minds of the PHP community. I&#8217;ve gotten a lot of help, pointers, code reviews etc by people from the community that helped me improve myself. Many of these I did not ask for, yet I&#8217;ve found it very helpful.</p>
<p><strong>What environment do you work on and what applications are important to  you?</strong></p>
<p>My personal preference is Apple computers with OSX. That environment allows me to work in the most efficient way. A good second choice, and the one I currently use at work, is an Ubuntu linux environment running KDE. The applications I run to help me in my work are an IDE (Zend Studio is my personal favorite), a MySQL frontend (phpMyAdmin is what I usually use), a webserver (Apache) with PHP installed with Xdebug. The main framework of choice would be symfony, with the help of additional components from Zend Framework, PEAR and ezComponents.</p>
<p><strong>If you could start over again from the moment you left high school,  what would you do different?</strong></p>
<p>I would do at least part-time study computer sciences to give me a better theoretical base on the development concepts I work with on a daily basis. But the thing that helps me most is the experience I built up over the years, so aside from that; I would not really do many things in a different way.</p>
<p><strong>Do you have any special hobbies or interests?</strong></p>
<p>Aside from PHP and Open Source, I like listening to music and read books.</p>
<p><strong>What are your plans for 2010 or the future in general?<br />
</strong><br />
I want to keep promoting best practices, and hope to improve the general level of knowledge in the PHP community.</p>
<p><strong>Quick answers, just answer in  max 5 words  when you read these words:</strong><br />
<strong>1.      IE</strong> &#8211; the bane of my existence<br />
<strong>2.      Apple </strong>- the ultimate operating system<br />
<strong>3.      Twitter</strong> &#8211; great communication and network channel<br />
<strong>4.      Face book</strong> &#8211; interesting platform<br />
<strong>5.      Analyze</strong> &#8211; important phase of any project<br />
<strong>6.      Layout</strong> &#8211; I&#8217;m more a back end guy<br />
<strong>7.      Religion</strong> &#8211; The root of all evil<br />
<strong>8.      Programming </strong>- Fantastic source of joy<br />
<strong>9.      Internet</strong> &#8211; Greatest invention ever</p>
<div class="shr-publisher-928"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/09/22/interview-stefan-koopmanschap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basic forms with Symfony</title>
		<link>http://www.devexp.eu/2009/04/30/basic-forms-with-symfony/</link>
		<comments>http://www.devexp.eu/2009/04/30/basic-forms-with-symfony/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 11:12:57 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=726</guid>
		<description><![CDATA[Our goal is to create a little crud that contains 4 fields id (auto increment integer) name (varchar 50) value (double) type (0 or 1) What I will explain is how to change your fields in the form after creation &#8230; <a href="http://www.devexp.eu/2009/04/30/basic-forms-with-symfony/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignright size-full wp-image-727" title="Symfony" src="http://www.devexp.eu/wp-content/uploads/2009/04/symfony.jpg" alt="Symfony" width="127" height="35" />Our goal is to create a little crud that contains 4 fields</p>
<p>id (auto increment integer)<br />
name (varchar 50)<br />
value (double)<br />
type (0 or 1)</p>
<p>What I will explain is how to change your fields in the form after creation with generation of a module. So we start with a clean module that contains 1 action class and 3 templates (new, edit and index) and 1 partial (form) that is included on the new and edit template.<br />
We created this module not by hand but with the very easy command: symfony propel:generate-module.</p>
<p><span id="more-726"></span>So what we want to do is quite easy, but if you are not used to working with forms, this is already a big struggle. So go to the action and you will see that in the executeNew method a form is initialized with an instance of a class (in our case DiscountForm).</p>
<pre class="brush: php; title: ; notranslate">
public function executeNew(sfWebRequest $request)
{
$this-&gt;form = new DiscountForm();
}
</pre>
<p>If you now go to the page in your browser you will see that the form is build up for you in a very basic way, containing no layout and just the 4 labels, the input fields and a submit button. If you want the user to see error messages when he has forgotten to fill in a required field or if you want to add a field to the form you can do that in the DiscountForm by adding a function configure().</p>
<pre class="brush: php; title: ; notranslate">
class DiscountForm extends BaseDiscountForm  {
public function configure() {
//insert extra data
}
}
</pre>
<p>Now, as we don&#8217;t want the user to select 0 or 1 when choosing his type, we let him use a dropdown with understandable content to choose from. 0 is discount and 1 is up count. The purpose of the type is that the number inserted in the value field will be added or subtracted.</p>
<p>To do this we create a public $type array containing the discount and up count in the Discount class in the model. We do this in the model class because, in this way, we can re-use this in other methods later as we might need this in the templates or other classes.</p>
<pre class="brush: php; title: ; notranslate">
static public $types = array(
'0' =&gt; 'Discount',
'1' =&gt; 'Up count',
);
</pre>
<p>And in the configure method we put this:</p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;widgetSchema['type'] = new sfWidgetFormChoice(array(
'choices'  =&gt; Discount::$types,
'expanded' =&gt; true,
));
</pre>
<p>If you reload your view on this point you will see that the type field has changed to a radio button field, which is easier to read.</p>
<p>You can style the form by adding some attributes to your fields:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php echo $form['discount']-&gt;render(array('class' =&gt; 'page-input', 'size' =&gt; 5));  ?&gt;
</pre>
<p>Page-input is the class specified in the css and giving the field a proper layout and size is the width of the field, in this case 5.<br />
All other attributes your element can accept can be inserted like this.</p>
<p>That&#8217;s actually it, if you followed these easy steps, you created your own basic crud. How nice it all looks will all depend on the css you use. For a few templates on forms you can take a look at <a href="http://www.smashingmagazine.com/2006/11/11/css-based-forms-modern-solutions/" target="_blank">this post </a></p>
<div class="shr-publisher-726"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/30/basic-forms-with-symfony/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony Form: unsetAllFieldsExcept()</title>
		<link>http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/</link>
		<comments>http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 12:37:31 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=706</guid>
		<description><![CDATA[When creating forms in symfony which extends from a Base (ORM) class, you sometimes do not need all fields that Propel/Doctrine generates for you. If you want to remove them you have several ways to do so. 1. Unset the &#8230; <a href="http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>When creating forms in symfony which extends from a Base (ORM) class, you sometimes do not need all fields that Propel/Doctrine generates for you. If you want to remove them you have several ways to do so.</p>
<p><b>1. Unset the fiels you don&#8217;t need.</b></p>
<pre class="brush: php; title: ; notranslate">
public function configure() {
  unset($this['field1'], $this['field2'], ... );
}
</pre>
<p>Simple way to remove the fields you don&#8217;t want, but if you change something in your database, which has an impact on that form (new column, foreignkey, etc ), it will be added in the (generated) super class. And if you don&#8217;t update the unset function with that extra field, it will be expected in the form. Unless you have unit tests for all your forms this could brake it without knowing it.</p>
<p><b>2. Override the setup function.</b></p>
<pre class="brush: php; title: ; notranslate">
/**
 * @override
 */
public function setup()
  {
    parent::setup();

    $this-&gt;setWidgets(...);

    $this-&gt;setValidators(...);
  }
</pre>
<p>Another way is to override the setup function and do your own widgets and validators initialization. This is a good way to only intialize the fields you really need, but you&#8217;ll have to do what your ORM generated for you.</p>
<p><b>3. Use a function which unsets all fields except the one you need (like the enableAllPluginsExcept function).</b></p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;unsetAllFieldsExcept(array(
      'field1',
      'field2',
      'field3',
      ...));
</pre>
<p>This would be usefull, because it will remove all fields you do not want to use, and even if new fields are added it will not use them. The drawback is that if you have 20 fields and only need to unset one of them, you&#8217;ll have more type work <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .<br />
Since it does not exist in symfony, I quickly created our own function. This function should be added in the class <u><em>BaseFormPropel.class</em></u>:</p>
<pre class="brush: php; title: ; notranslate">
abstract class BaseFormPropel extends sfFormPropel
{
  public function setup() {
  }

  protected function unsetAllFieldsExcept($fields = array()) {

    $unsetFields = array_diff(array_keys($this-&gt;getWidgetSchema()-&gt;getFields()), $fields);

    foreach($unsetFields as $value) {
      unset($this[$value]);
    }
  }
}
</pre>
<p><b>Which one to use ?</b><br />
None of them are better. But if you need to reset a majority of the fields the ORM has generated then I would go for the method 2. If you only need to unset the fields you do not want to use then I would use the function unsetAllFieldsExcept().</p>
<p>Which method do/would you use ?</p>
<div class="shr-publisher-706"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>sfWidgetFormInputCheckbox unchecked bug</title>
		<link>http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/</link>
		<comments>http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 12:33:37 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[sfWidgetFormInputCheckbox]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=681</guid>
		<description><![CDATA[Ever tried to create a Symfony form with a check box input field, which by default should be unchecked ? No ? Well read on because it&#8217;s not that easy . This would be the code to print a check &#8230; <a href="http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Ever tried to create a Symfony form with a check box input field, which by default should be unchecked ? No ? Well read on because it&#8217;s not that easy <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>This would be the code to print a check box input field in a Symfony form:</p>
<pre class="brush: php; title: ; notranslate">
class CheckboxForm extends BaseCheckboxForm {
 public function configure() {
 $this-&gt;widgetSchema['field'] = new sfWidgetFormInputCheckbox();
 }
}
</pre>
<p>When you use the form to create something then by default the check box should be unchecked. And when you use this form for editing, then the check box should be checked if the object you try to edit has already been checked in the past.</p>
<p>If you try this code, you&#8217;ll see that the check box will always be checked. Even if you display this form to create a new object. Strange no ?</p>
<p><span id="more-681"></span></p>
<p>The problem is due to a bug in the Symfony sfWidgetFormInputCheckbox class. Even worse, this bug has been reported the first time 10 months ago (<a href="http://trac.symfony-project.org/ticket/3917" target="_blank">trac #3917</a>) and 1 month later (<a href="http://trac.symfony-project.org/ticket/3996" target="_blank">trac #3996</a>) and it&#8217;s still not fixed ! (grrrrr)</p>
<p>Until Symfony bug fixes this issue, there are 2 work a rounds you can use.</p>
<p><strong>1. Edit the sfWidgetFormInputCheckbox class and patch it:</strong></p>
<p><em>actual</em></p>
<pre class="brush: php; title: ; notranslate">
class sfWidgetFormInputCheckbox extends sfWidgetFormInput
{
 ...
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
 if (!is_null($value) &amp;&amp; $value !== false)
 {
 $attributes['checked'] = 'checked';
 }
 ...
 }
}
</pre>
<p><em>patched</em></p>
<pre class="brush: php; title: ; notranslate">
class sfWidgetFormInputCheckbox extends sfWidgetFormInput
{
 ...
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
 if (!is_null($value) &amp;&amp; $value !== false &amp;&amp; $value != 0)
 {
 $attributes['checked'] = 'checked';
 }
 ...
 }
}
</pre>
<p>I would not recommend this, because if like us, you have more than one Symfony environment, there is a chance that you could forget to patch it. And worse if Symfony releases a new version without the bug fix you&#8217;ll have to remember to re patch the file.</p>
<p><strong>2. Extend the sfWidgetFormInputCheckbox class and override the render method:</strong></p>
<p><em>Edit: Put this class in the lib folder and call it myOwnWidgetFormInputCheckbox.class.php. After that run symfony cc.</em></p>
<pre class="brush: php; title: ; notranslate">
/**
 * FIXME: This class can be removed if the sfWidgetFormInputCheckbox bug
 * has been resolved in symfony.
 */
class myOwnWidgetFormInputCheckbox extends sfWidgetFormInputCheckbox
{
 /**
 * Override render method due to symfony bug (http://trac.symfony-project.org/ticket/3917)
 */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
 if (!is_null($value) &amp;&amp; $value !== false &amp;&amp; $value != 0)
 {
 $attributes['checked'] = 'checked';
 } 

 if (!isset($attributes['value']) &amp;&amp; !is_null($this-&gt;getOption('value_attribute_value'))) {
 $attributes['value'] = $this-&gt;getOption('value_attribute_value');
 }

 return parent::render($name, null, $attributes, $errors);
 }
}
</pre>
<p>Your form class should then be changed to:</p>
<pre class="brush: php; title: ; notranslate">
class CheckboxForm extends BaseCheckboxForm {
 public function configure() {
 $this-&gt;widgetSchema['field'] = new myOwnWidgetFormInputCheckbox();
 }
}
</pre>
<p>This was very easy to solve, but we lost a lot of time in finding the reason why this stupido check box was always checked. And why the hell is this bug still not solved in Symfony ?</p>
<p>In the mean time patch your symfony or create your own checkbox widget <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<div class="shr-publisher-681"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Interesting People &#8211; part 1: Fabien Potencier</title>
		<link>http://www.devexp.eu/2009/04/04/interesting-people-part-1-fabien-potencier/</link>
		<comments>http://www.devexp.eu/2009/04/04/interesting-people-part-1-fabien-potencier/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 09:03:21 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[fabien Potencier]]></category>
		<category><![CDATA[lead developer]]></category>
		<category><![CDATA[sensio]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=543</guid>
		<description><![CDATA[Nothing better to get inspiration from then a nice cup of Nespresso in the evening. We are working with Symfony for a few months (years) now and I was wondering earlier this day: Who are the guys that are able &#8230; <a href="http://www.devexp.eu/2009/04/04/interesting-people-part-1-fabien-potencier/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignright" style="border: 0pt none; margin: 5px;" title="Fabien Potencier" src="http://it-republik.de/konferenzen/rueckblick/php/ipc2007/images/2352.jpg" alt="Fabien Potencier" width="130" height="160" />Nothing better to get inspiration from then a nice cup of Nespresso in the evening. We are working with Symfony for a few months (years) now and I was wondering earlier this day: Who are the guys that are able to produce such a nice piece of software? You got to admit it that the framework these guys created is a masterpiece, must be a shitload of work and it is still growing on a daily basis.</p>
<p>Off course there is more then one person creating this software, but 1 man in particular is leading this project: Fabien Potencier.</p>
<p><span id="more-543"></span>A little history:</p>
<p>1994 to 1997  Fabien went to the Ecole National Supérieure des Mines de Nancy.<br />
1997 to 1998  Added master entrepreneur at HEC School of Management to his curriculum vitae.</p>
<p>In June 1998 Fabien and Grégory Pascal created there own little company called Sensio in France, an office was created in Canada and the United States. In October 2005 the Symfony framework was licensed and two years later the first version was launched.</p>
<p>A little list of history of Symfony:</p>
<blockquote><p>10/2005:            launch of the Symfony framework licence under MIT</p>
<p>11/2005:            Support integration of Ajax</p>
<p>12/2005:            Launch of the Askeet tutorial</p>
<p>08/2006:            Announcement of the first version</p>
<p>10/2006:            Announcement of the implication of Yahoo! Inc. in the framework and launch of the Yahoo! Bookmarks in Symfony</p>
<p>01/2007:            The definitive guide to Symfony is for sale as a paperback</p>
<p>02/2007:            The first version 1.0 is launched</p>
<p>09/2007:            The first exclusive conference takes place, SymfonyCamp in Holland</p>
<p>07/2008:            Yahoo! Launches the new version of delicious in Symfony</p></blockquote>
<p>Fabien launched his new book recently at the end of 2008, Practical Symfony and is actually an updated version of the first book, the definitive guide to Symfony.</p>
<p>Just like the first website Askeet, a new site was launched with the updates and new technologies, described in the second book, called: Jobeet.</p>
<p>This gives you an easy walkthrough for Symfony in 24 days and is the best way to understand and learn the structure and class system.</p>
<p>I know that this isn&#8217;t a full biography of Fabien Potencier but it will give you an idea of what he created and the work he is doing.</p>
<p>Follow Symfony the next few year, it has a great future&#8230; at least that is what I think.</p>
<div class="shr-publisher-543"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/04/interesting-people-part-1-fabien-potencier/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Symfony Forms Framework: Merge 2 forms</title>
		<link>http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/</link>
		<comments>http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 11:02:22 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=462</guid>
		<description><![CDATA[Recently I had to create a form to create/update users in our system. Some time ago we decided to save are users in 2 tables. The first table would contain all login information and the second his personal information. This &#8230; <a href="http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Recently I had to create a form to create/update users in our system. Some time ago we decided to save are users in 2 tables. The first table would contain all login information and the second his personal information. This is a simple example of the DB design:</p>
<div id="attachment_463" class="wp-caption aligncenter" style="width: 498px"><img class="size-full wp-image-463" title="User db design" src="http://www.devexp.eu/wp-content/uploads/2009/03/dbdesign.png" alt="User db design" width="488" height="168" /><p class="wp-caption-text">User db design</p></div>
<p>I would not recommend doing this for so little fields. But in our system we have a lot more fields, and it helps us to optimize our queries.</p>
<p>Wouldn&#8217;t it be better if we could merge the 2 forms? The answer is yes. And it&#8217;s pretty easy to do so in Symfony &#8230; too bad that it’s not documented on the Symfony website.</p>
<p><span id="more-462"></span></p>
<p>When you generate the forms with Symfony, you’ll get a UserForm and a UserInfoForm.</p>
<pre class="brush: php; title: ; notranslate">/**
* User form.
*
* @package    form
*/
class UserForm extends BaseUserForm {

public function configure() {

}

}

/**
* UserInfo form.
*
* @package    form
*/
class UserInfoForm extends BaseUserInfoForm {

public function configure() {

}

}</pre>
<p>The idea is to display one form to insert/update those 2 tables. If you are familiar to creating forms with Symfony you know that you could achieve it by instantiating the 2 forms in an action and send them to the templates:</p>
<pre class="brush: php; title: ; notranslate">
/**
* Action Class
*/
class userActions extends sfActions
{
public function executeCreate($request) {
$this-&gt;userForm = new UserForm();
$this-&gt;userInfoForm = new UserInfoForm();
$this-&gt;setTemplate('edit');
}

public function executeEdit($request) {
$this-&gt;userForm = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));
$this-&gt;userInfoForm = new UserInfoForm(UserInfoPeer::retrieveByPK($request-&gt;getParameter('id')));
}

public function executeUpdate($request) {
$this-&gt;userForm = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));
$this-&gt;userInfoForm = new UserInfoForm(UserInfoPeer::retrieveByPK($request-&gt;getParameter('id')));

$this-&gt;userForm-&gt;bind($request-&gt;getParameter($this-&gt;userForm-&gt;getName()));
$this-&gt;userInfoForm-&gt;bind($request-&gt;getParameter($this-&gt;userInfoForm-&gt;getName()));

// etc ...
}
}

// Template code editSuccess.php
&lt;?php $user = $userForm-&gt;getObject(); ?&gt;

&lt;form action=&quot;&lt;?php echo url_for('user/update'.(!$user-&gt;isNew() ? '?id='.$user-&gt;getId() : '')) ?&gt;&quot; method=&quot;post&quot;&gt;
&lt;table&gt;
&lt;tfoot&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tfoot&gt;
&lt;tbody&gt;
&lt;?php echo $userForm ?&gt;
&lt;?php echo $userInfoForm ?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/form&gt;
</pre>
<p>This is really annoying to work this way. You always have to instance 2 forms in the action and the templates. Wouldn&#8217;t it be better if we could merge the 2 forms? The answer is yes. And it&#8217;s pretty easy to do so in Symfony &#8230; too bad that it’s not documented on the Symfony website.</p>
<p>Here is how you do it:</p>
<p><span style="text-decoration: underline;"><strong>1. UserForm.class.php</strong></span></p>
<pre class="brush: php; title: ; notranslate">/**
* User form.
*
* @package    form
*/
class UserForm extends BaseUserForm {

public function configure() {
$this-&gt;mergeForm(new UserInfoForm(UserInfoPeer::retrieveByPK($this-&gt;getObject()-&gt;getId())));
}

/**
* Override the save method to save the merged user info form.
*/
public function save($con = null) {
parent::save();

$this-&gt;updateUserInfo();

return $this-&gt;object;
}

/**
* Updates the user info merged form.
*/
protected function updateUserInfo() {
// update user info
if (!is_null($userInfo = $this-&gt;getUserInfo())) {

$values = $this-&gt;getValues();
if ( $userInfo-&gt;isNew() ) {
$values['user_id'] = $this-&gt;object-&gt;getId();
}

$userInfo-&gt;fromArray($values, BasePeer::TYPE_FIELDNAME);

$userInfo-&gt;save();
}
}

/**
* Returns the user info object. If it does
* not exist return a new instance.
*
* @return UserInfo
*/
protected function getUserInfo() {

if (!$this-&gt;object-&gt;getUserInfo()) {
return new UserInfo();
}

return $this-&gt;object-&gt;getUserInfo();
}
}
</pre>
<p><span style="text-decoration: underline;"><strong>2. actions.class.php</strong></span></p>
<pre class="brush: php; title: ; notranslate">
public function executeCreate($request) {
$this-&gt;form = new UserForm();
$this-&gt;setTemplate('edit');
}

public function executeEdit($request) {
$this-&gt;form = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));
}

public function executeUpdate($request) {

$this-&gt;forward404Unless($request-&gt;isMethod('post'));

$this-&gt;form = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));

$this-&gt;form-&gt;bind($request-&gt;getParameter($this-&gt;form-&gt;getName()));
if ($this-&gt;form-&gt;isValid()) {
$user = $this-&gt;form-&gt;save();
$this-&gt;redirect('user/edit?id='.$user-&gt;getId());
}

$this-&gt;setTemplate('edit');
}
</pre>
<p><span style="text-decoration: underline;"><strong>3. editSuccess.php</strong></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php $user = $userForm-&gt;getObject(); ?&gt;

&lt;form action=&quot;&lt;?php echo url_for('user/update'.(!$user-&gt;isNew() ? '?id='.$user-&gt;getId() : '')) ?&gt;&quot; method=&quot;post&quot;&gt;
&lt;table&gt;
&lt;tfoot&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tfoot&gt;
&lt;tbody&gt;
&lt;?php echo $userForm ?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/form&gt;
</pre>
<p>As you can see, it’s the UserForm that will handle all the business of the UserInfoForm. This is great because the code in the action and template will be much more lightened and if needed it can easily be reused somewhere else.</p>
<p>This was a simple example on how to merge 2 forms, but since it&#8217;s not documented on the symfony website, it took me some time to fully understand on how to make it work. Now you can do much more advanced operations. <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="shr-publisher-462"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Symfony Forms Framework: Change validators at runtime.</title>
		<link>http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/</link>
		<comments>http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 09:34:12 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=374</guid>
		<description><![CDATA[Let’s say you have to make a user form with password fields. When you create the user you want the password fields to be required, but on an update the password fields should be optional because you don’t want the &#8230; <a href="http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Let’s say you have to make a user form with password fields. When you create the user you want the password fields to be <strong>required</strong>, but on an update the password fields should be <strong>optional</strong> because you don’t want the user the fill in his password on each update.</p>
<p>This is tricky because in the symfony forms Framework you have to predefine your validators. Your form would look like this:</p>
<pre class="brush: php; title: ; notranslate">
class UserForm extends BaseUserForm {

  public function configure() {
    // Widgets
    $this-&gt;widgetSchema['password'] = new sfWidgetFormInputPassword();
    $this-&gt;widgetSchema['password_again'] = new sfWidgetFormInputPassword();

    // Validators
    $this-&gt;validatorSchema['password']-&gt;setOption('required', false);
    $this-&gt;validatorSchema['password_again'] = clone $this-&gt;validatorSchema['password'];

    $this-&gt;widgetSchema-&gt;moveField('password_again', 'after', 'password');

    $this-&gt;mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again', array(), array('invalid' =&gt; 'The two passwords must be the same.')));
  }

}
</pre>
<p>In this signature of the form I defined the password and password_again field as optional, which is correct for an update of the user, but incorrect for the creation of the user. How the hell can I change the validator of the password field when I create a user ?</p>
<p>Well thanks to the good and well designed framework of symfony it is very simple <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<pre class="brush: php; title: ; notranslate">
class UserForm extends BaseUserForm {

  public function configure() {
    // Widgets
    $this-&gt;widgetSchema['password'] = new sfWidgetFormInputPassword();
    $this-&gt;widgetSchema['password_again'] = new sfWidgetFormInputPassword();

    // Validators
    $this-&gt;validatorSchema['password']-&gt;setOption('required', false);
    $this-&gt;validatorSchema['password_again'] = clone $this-&gt;validatorSchema['password'];

    $this-&gt;widgetSchema-&gt;moveField('password_again', 'after', 'password');

    $this-&gt;mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again', array(), array('invalid' =&gt; 'The two passwords must be the same.')));
  }

  public function bind(array $taintedValues = null, array $taintedFiles = null) {

    if ( $this-&gt;object-&gt;isNew() ) {
      $this-&gt;validatorSchema['password']-&gt;setOption('required', true);
    }

    parent::bind($taintedValues, $taintedFiles);
  }

}
</pre>
<p>What I did is override the function <em>bind</em> and before calling the bind method of the parent, I checked if the user object is new (means that we create a user) and if this is the case set the required option of the password field to true. </p>
<div class="shr-publisher-374"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>symfony 1.3</title>
		<link>http://www.devexp.eu/2009/01/26/symfony-13/</link>
		<comments>http://www.devexp.eu/2009/01/26/symfony-13/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 07:39:47 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=307</guid>
		<description><![CDATA[symfony announced a new release in November 2009 and will be going from 1.2 to 1.3. It’s wonderful that these guys are thinking ahead and keeping us up to date. Why is this important, you ask? Well would you invest &#8230; <a href="http://www.devexp.eu/2009/01/26/symfony-13/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignright" style="border: 0pt none; margin-left: 5px; margin-right: 5px;" title="Symfony" src="http://www.symfony-project.org/downloads/logos/symfony.gif" alt="" width="250" />symfony announced a new release in November 2009 and will be going from 1.2 to 1.3.</p>
<p>It’s wonderful that these guys are thinking ahead and keeping us up to date. Why is this important, you ask? Well would you invest in software that isn’t trying to evolve to a better version, to a more reliable version? I don’t think so. Like in our case: We started developing software in October 2007 and needed a part of the project to be PHP-based. The choice of framework wasn’t that easy but the great documentation and the future developments convinced us to use symphony. And we didn’t regret our choice for one minute. Fabien Potencier and his crew keep their promises to the developers and users.</p>
<p>I can quote him as they give good reasons why they should keep us up to date:</p>
<ul>
<li>the users will have time to learn all the great symfony 1.2 features compared to symfony 1.0</li>
<li>the core team will have plenty of time to make symfony 1.3 rock solid</li>
<li>the documentation team will have time to write even more tutorials and blog posts</li>
<li>the plugin developers will have plenty of time to upgrade their plugins to 1.2 with confidence that their work will still be relevant for 1.3.</li>
</ul>
<p>Great work guys, keep us up to date, in the mean time we’ll do just fine with the 1.2 version.</p>
<div class="shr-publisher-307"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/01/26/symfony-13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

