<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://prendreuncafe.com/blog/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Prendre un Café - Tag - bestpractices</title>
  <link>http://prendreuncafe.com/blog/</link>
  <atom:link href="http://prendreuncafe.com/blog/feed/tag/bestpractices/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>fr</language>
  <pubDate>Thu, 04 Sep 2008 20:06:32 +0200</pubDate>
  <copyright>Contenus sous licence Creative Commons BY-SA</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Comment faire fuir à coup sûr vos utilisateurs ?</title>
    <link>http://prendreuncafe.com/blog/post/2008/08/24/Comment-faire-fuir-a-coup-sur-vos-utilisateurs</link>
    <guid isPermaLink="false">urn:md5:3a3c403335eef28f603dc8c9c9ec3e78</guid>
    <pubDate>Sun, 24 Aug 2008 15:45:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Divers</category>
        <category>bestpractices</category><category>ergonomie</category><category>formulaires</category><category>grumph</category><category>nimp</category><category>web</category>    
    <description>    &lt;p&gt;C&amp;#8217;est bien connu, il est déjà sufisament dur de faire (re)venir des utilisateurs sur vos services en ligne pour ne pas les faire partir à la moindre occasion. C&amp;#8217;est pourtant ce que fait un site dédié à la guitare que j&amp;#8217;ai tenté de consulter récemment. Connaissant les tendances dérivistes des services juridiques de certaines entités, je m&amp;#8217;abstiendrai donc de faire un lien hypertexte direct vers ce dernier, et même de le citer textuellement&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/08/24/#pnote-990-1&quot; id=&quot;rev-pnote-990-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;Je tombe sur ce site, qui propose apparemment moult ressources sur l&amp;#8217;instrument et qui m&amp;#8217;intéressent potentiellement, mais au moment de consulter l&amp;#8217;article objet de ma convoitise, on me notifie du message suivant&amp;#160;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Ergonomie/GuitareLive/registration_obligatoire.png&quot; alt=&quot;registration_obligatoire.png&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Jusque-là, rien de profondément choquant même si on peut imaginer que nombre d&amp;#8217;internautes ne s&amp;#8217;embêteront pas à créer un compte pour consulter la ressource et passeront à la concurrence&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/08/24/#pnote-990-2&quot; id=&quot;rev-pnote-990-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;Allez, je suis dans un bon jour, je demande la création d&amp;#8217;un compte. Je me retrouve face à un formulaire assez copieux, exigeant bien entendu des informations hautement nécessaires pour consulter un tutoriel de guitare comme ma localisation géographique, mon nom de famille, ma date de naissance, sans oublier bien entendu les inévitables propositions d&amp;#8217;abonnement à des newsletter très étroitement liées à la pratique de la guitare&amp;#160;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Ergonomie/GuitareLive/pollution.png&quot; alt=&quot;pollution.png&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Sentant le SPAM arriver à grand pas, je rentre mon email suffixé pour &lt;a href=&quot;http://www.seandeasy.com/multiple-email-addresses-for-one-gmail-account/&quot; hreflang=&quot;en&quot;&gt;détecter a posteriori le service à l&amp;#8217;origine d&amp;#8217;éventuels courriels indésirables reçus&lt;/a&gt;. Ben non&amp;#160;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Ergonomie/GuitareLive/wrong_email_validation.png&quot; alt=&quot;wrong_email_validation.png&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Vous noterez le plus fort, c&amp;#8217;est que non seulement le service n&amp;#8217;est pas à même de valider convenablement une adresse email (le signe + est acceptable), mais en plus on me soupçonne ouvertement de SPAM potentiel.&lt;/p&gt;


&lt;p&gt;Normalement, à ce stade, &lt;em&gt;je me casse sur Mars&lt;/em&gt;, comme on dit. Mais pour la beauté de l&amp;#8217;exercice, je &lt;em&gt;corrige&lt;/em&gt; mon adresse email, pérsévère en entrant un mot de passe et valide à nouveau le formulaire&amp;#160;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Ergonomie/GuitareLive/restricted_chars.png&quot; alt=&quot;restricted_chars.png&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Oui, cela commence à faire beaucoup. Je ne réexpliquerai pas ici pourquoi &lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/06/04/Demander-a-restreindre-les-caracteres-utilises-dans-les-mots-de-passe-est-idiot&quot; hreflang=&quot;fr&quot;&gt;limiter les caractères dans les mots de passe est idiot&lt;/a&gt;, cela a déjà été fait ici-même précédemment.&lt;/p&gt;


&lt;p&gt;Toujours dans la perspective de poursuivre cette expérience amusante, j&amp;#8217;arrive enfin à valider le formulaire sans retours d&amp;#8217;erreur et m&amp;#8217;identifie donc sur le service pour consulter la ressource en question. Patatra&amp;#160;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Ergonomie/GuitareLive/abo_obligatoire.png&quot; alt=&quot;abo_obligatoire.png&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Non seulement la création d&amp;#8217;un compte était obligatoire, mais maintenant il faut s&amp;#8217;abonner (c&amp;#8217;est à dire &lt;em&gt;payer&lt;/em&gt;) pour consulter la ressource en question, chose qui n&amp;#8217;avait été aucunement stipulée auparavant. Sachant bien entendu qu&amp;#8217;à ce stade, je n&amp;#8217;ai toujours &lt;strong&gt;aucune&lt;/strong&gt; idée de la qualité des contenus proposés par le site.&lt;/p&gt;


&lt;p&gt;Bref, je leur souhaite malgré tout un avenir comptable radieux, même si je ne peux m&amp;#8217;empêcher de pouffer à l&amp;#8217;idée du chiffre d&amp;#8217;affaire généré par le se(r)vice.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/08/24/#rev-pnote-990-1&quot; id=&quot;pnote-990-1&quot;&gt;1&lt;/a&gt;] Mais les curieux trouveront bien entendu sans peine le site en question.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/08/24/#rev-pnote-990-2&quot; id=&quot;pnote-990-2&quot;&gt;2&lt;/a&gt;] Sur le Web, vous avez quasiment systématiquement un concurrent qui propose la même chose que vous gratuitement. C&amp;#8217;est comme ça, et c&amp;#8217;est aussi un peu pour ça que c&amp;#8217;est chouette.&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
          <comments>http://prendreuncafe.com/blog/post/2008/08/24/Comment-faire-fuir-a-coup-sur-vos-utilisateurs#comment-form</comments>
      <wfw:comment>http://prendreuncafe.com/blog/post/2008/08/24/Comment-faire-fuir-a-coup-sur-vos-utilisateurs#comment-form</wfw:comment>
      <wfw:commentRss>http://prendreuncafe.com/blog/feed/rss2/comments/990</wfw:commentRss>
      </item>
    
  <item>
    <title>Mes conventions de codage...</title>
    <link>http://prendreuncafe.com/blog/post/2008/07/23/Mes-conventions-de-codage</link>
    <guid isPermaLink="false">urn:md5:b94a814a2f724b5abe17d299a6dfc06a</guid>
    <pubDate>Wed, 23 Jul 2008 21:21:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>bestpractices</category><category>php</category>    
    <description>    &lt;p&gt;... sont celles des projets sur lesquels je me greffe. C'est en effet pour moi une forme de respect que d'appliquer les standards de codage partagés par une communauté (ou une équipe) de développeurs : ainsi, on maximise les chances de se comprendre et on minimise les coûteuses phases de communication entre geeks introvertis&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/23/#pnote-988-1&quot; id=&quot;rev-pnote-988-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; &lt;img src=&quot;/blog/themes/Puc4/smilies/tongue.gif&quot; alt=&quot;:p&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;En effet, rien de plus pénible que de reprendre le code de quelqu'un qui a pris des libertés avec des conventions établies à ce niveau, l'apothéose étant obtenue avec ce genre de code :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; Ma_superClasse &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; dire_coucou &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$popol&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'coucou '&lt;/span&gt; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$popol&lt;/span&gt;   . &lt;span style=&quot;color: #ff0000;&quot;&gt;' !'&lt;/span&gt; ;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
     &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; DireAuRevoir&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$Popol&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;a href=&quot;http://www.php.net/print&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;print&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Au revoir $Popol !&amp;quot;&lt;/span&gt;;
     &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Je force bien évidemment ici le trait, mais tout le monde est déjà tombé sur ce genre de code illisible, qui multiplie par 10 votre temps d'intervention sur ce dernier et divise par 1000 votre passion pour la &lt;acronym title=&quot;Tierce Maintenance Applicative&quot;&gt;TMA&lt;/acronym&gt;.&lt;/p&gt;


&lt;p&gt;Bien entendu, il peut arriver de produire du code sur un projet ne nécessitant l'utilisation d'aucune brique logicielle existante. Auquel cas vous pouvez librement appliquer vos propres standards de codage, l'important étant ici qu'ils soient cohérents et constamment appliqués. S'il peuvent être ceux d'un projet open source existant reconnu, cela augmentera la sympathie potentielle à votre égard de futurs intervenants sur votre code &lt;img src=&quot;/blog/themes/Puc4/smilies/wink.gif&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Je noterai quand même en vrac quelques bonnes pratiques générales globalement reconnues et appréciées :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;être explicite,&lt;/li&gt;
&lt;li&gt;indenter son code,&lt;/li&gt;
&lt;li&gt;documenter son code,&lt;/li&gt;
&lt;li&gt;à choisir entre les deux, privilégier la lisibilité à la concision,&lt;/li&gt;
&lt;li&gt;utiliser des noms de variables, de classes, de méthodes, de fonctions et d'arguments parlants,&lt;/li&gt;
&lt;li&gt;utiliser des noms anglophones,&lt;/li&gt;
&lt;li&gt;utiliser des motifs de conception connus.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Personnellement, j'ai mes petites préférences et tout comme &lt;a href=&quot;http://case.oncle-tom.net/&quot; hreflang=&quot;fr&quot;&gt;Oncle Tom&lt;/a&gt; - qui m'a gentiment refilé &lt;a href=&quot;http://case.oncle-tom.net/2008/07/23/conventions-de-programmation-necessaire-maturite/&quot; hreflang=&quot;fr&quot;&gt;cette chaîne&lt;/a&gt;&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/23/#pnote-988-2&quot; id=&quot;rev-pnote-988-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt; - j'ai tendance à appliquer les &lt;a href=&quot;http://trac.symfony-project.org/wiki/HowToContributeToSymfony#CodingStandards&quot; hreflang=&quot;en&quot;&gt;standards de codage de symfony&lt;/a&gt;, que je trouve homogènes et cohérents. Mais ce sont là bien évidemment essentiellement des questions de goûts et de couleurs.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/23/#rev-pnote-988-1&quot; id=&quot;pnote-988-1&quot;&gt;1&lt;/a&gt;] Voire les trolls genre &lt;em&gt;les tabulations ça pue, vive l'indentation à trois espaces&lt;/em&gt;...&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/07/23/#rev-pnote-988-2&quot; id=&quot;pnote-988-2&quot;&gt;2&lt;/a&gt;] Salopard, ça va se payer ! &lt;img src=&quot;/blog/themes/Puc4/smilies/wink.gif&quot; alt=&quot;;-)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Demander à restreindre les caractères utilisés dans les mots de passe est idiot</title>
    <link>http://prendreuncafe.com/blog/post/2008/06/04/Demander-a-restreindre-les-caracteres-utilises-dans-les-mots-de-passe-est-idiot</link>
    <guid isPermaLink="false">urn:md5:f0b1a6866f144db2f77ede15d40d6c37</guid>
    <pubDate>Wed, 04 Jun 2008 12:25:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Divers</category>
        <category>bestpractices</category><category>ergonomie</category><category>password</category><category>security</category>    
    <description>    &lt;p&gt;Voulant créer un compte sur un nouveau service en ligne, j'ai eu la désagréable surprise d'obtenir ce message d'erreur au moment de la validation de mon mot de passe :&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;Password may only contain alphanumeric characters&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;Pour les anglophobes, on me demande de n'utiliser que des caractères alphanumériques pour mon mot de passe.&lt;/p&gt;


&lt;p&gt;Ce n'est pas la première fois que je tombe sur la mise en place de pareil procédé. Quel est l'intérêt d'imposer cette limitation ? Je pense que plus un mot de passe utilise une plage de caractères diversifiée, plus il est sécurisé. Je peux éventuellement imaginer les problèmes que pourraient poser l'utilisation de caractères codés sur deux octets, ou encore l'angoisse d'une faille XSS potentielle chez les plus paranos, mais de là à interdire purement et simplement les tirets, underscores, espaces&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/06/04/#pnote-974-1&quot; id=&quot;rev-pnote-974-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;, je trouve ça tout simplement &lt;strong&gt;idiot à tomber par terre&lt;/strong&gt;.&lt;/p&gt;


&lt;p&gt;Voila, c'est dit.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Edit :&lt;/strong&gt; &lt;a href=&quot;http://googleblog.blogspot.com/2008/06/does-your-password-pass-test.html&quot; hreflang=&quot;en&quot;&gt;Quelques astuces sur la sécurisation des mots de passe&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/06/04/#rev-pnote-974-1&quot; id=&quot;pnote-974-1&quot;&gt;1&lt;/a&gt;] Alors que &lt;a href=&quot;http://www.baekdal.com/articles/usability/password-security-usability/&quot; hreflang=&quot;en&quot;&gt;l'utilisation de deux espaces dans un mot de passe est très sécurisante&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>QOTD</title>
    <link>http://prendreuncafe.com/blog/post/2008/05/04/QOTD</link>
    <guid isPermaLink="false">urn:md5:7b40bbbd9d40f96105e19c63b5b0fc59</guid>
    <pubDate>Sun, 04 May 2008 16:38:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>architecture</category><category>bestpractices</category><category>framework</category><category>quote</category><category>scale</category>    
    <description>    &lt;p&gt;Une belle quote comme ça, je me la note dans un coin pour la ressortir la prochaine fois qu'on trolle sur les performances du &lt;em&gt;framework X&lt;/em&gt; ou du &lt;em&gt;langage Y&lt;/em&gt; :&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;Languages, libraries and frameworks don't scale. Architectures do.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;En français approchant :&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;Les langages de programmation, les librairies et les frameworks ne tiennent pas la charge. Les architectures, si.&lt;/p&gt;&lt;/blockquote&gt;


&lt;p&gt;(&lt;a href=&quot;http://pownce.com/ubernostrum/notes/2043798/&quot; hreflang=&quot;en&quot;&gt;via&lt;/a&gt;, apparement attribuable à &lt;a href=&quot;http://www.iamcal.com/&quot; hreflang=&quot;en&quot;&gt;Cal Henderson&lt;/a&gt;)&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Symfony 1.1 beta, tour du propriétaire - L'internationalisation (i18n)</title>
    <link>http://prendreuncafe.com/blog/post/2008/03/13/Symfony-11-beta-tour-du-proprietaire-Linternationalisation-i18n</link>
    <guid isPermaLink="false">urn:md5:4646e60529b4ae4cc53445b5d6cf0103</guid>
    <pubDate>Thu, 13 Mar 2008 11:52:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>bestpractices</category><category>framework</category><category>i18n</category><category>php</category><category>symfony</category><category>tutoriel</category>    
    <description>    &lt;p&gt;Dans la liste des tâches nouvellement ajoutées en Symfony 1.1, on remarque une section dédiée à l'internationalisation :&lt;/p&gt;


&lt;pre&gt;i18n
  :extract            Extracts i18n strings from php files
  :find               Finds non &amp;quot;i18n ready&amp;quot; strings in an application&lt;/pre&gt;


&lt;p&gt;Et oui, la fonctionnalité dont tous les gens qui ont un jour travaillé sur des applications internationalisées en Symfony 1.0 ont rêvé a enfin été ajoutée : une tâche d'extraction des chaînes de caractères à traduire, avec génération et mise à jour des fichiers de traductions &lt;a href=&quot;http://developers.sun.com/dev/gadc/technicalpublications/articles/xliff.html&quot; hreflang=&quot;en&quot;&gt;XLIFF&lt;/a&gt; &lt;img src=&quot;/blog/themes/Puc4/smilies/smile.gif&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Si vous avez suivi les &lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/Symfony-11-beta-tour-du-proprietaire-Installation&quot; hreflang=&quot;fr&quot;&gt;précédents&lt;/a&gt; &lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/Symfony-11-beta-tour-du-proprietaire-Les-formulaires&quot; hreflang=&quot;fr&quot;&gt;tutoriels&lt;/a&gt;, vous devez disposer d'un projet &lt;code&gt;sf11test&lt;/code&gt;, d'une application &lt;code&gt;main&lt;/code&gt; et d'un module &lt;code&gt;contact&lt;/code&gt;.&lt;/p&gt;


&lt;p&gt;On va activer la gestion de l'internationalisation dans l'application en éditant le fichier de configuration &lt;code&gt;apps/main/config/settings.yml&lt;/code&gt; comme suit :&lt;/p&gt;

&lt;pre&gt;
[...]
all:
  [...]
  .settings:
    [...]
    i18n:                   on
    [...]
    standard_helpers:       [Partial, Cache, Form, I18N]
    [...]
    default_culture:        en
&lt;/pre&gt;


&lt;p&gt;On part du principe que la langue par défaut sera l'anglais (en). Ajoutons quelques chaînes internationalisées dans le template &lt;code&gt;apps/main/modules/contact/templates/indexSuccess.php&lt;/code&gt; au moyen du helper &lt;code&gt;__()&lt;/code&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&amp;lt;h2&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; __&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Contact us'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; __&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Drop us a message using the form below:'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;form action=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;?php echo url_for('contact/index') ?&amp;gt;&amp;quot;&lt;/span&gt; method=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&amp;gt;
  &amp;lt;table&amp;gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;input type=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; value=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;?php echo __('Send your message') ?&amp;gt;&amp;quot;&lt;/span&gt; /&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;
&amp;lt;/form&amp;gt;&lt;/pre&gt;


&lt;p&gt;Maintenant, lançons la commande d'extraction des chaînes à traduire pour notre future version française, en lui demandant poliment de générer automatiquement le fichier de traduction et de supprimer automatiquement les entrées orphelines :&lt;/p&gt;

&lt;pre&gt;
 $ ./symfony i18n:extract --auto-save --auto-delete main fr
&amp;gt;&amp;gt; i18n      extracting i18n strings for the &amp;quot;main&amp;quot; application
&amp;gt;&amp;gt; i18n      found &amp;quot;3&amp;quot; new i18n strings
&amp;gt;&amp;gt; i18n      found &amp;quot;0&amp;quot; old i18n strings
&amp;gt;&amp;gt; i18n      saving new i18n strings
&amp;gt;&amp;gt; i18n      deleting old i18n strings
&lt;/pre&gt;


&lt;p&gt;Le fichier &lt;code&gt;apps/main/i18n/fr/messages.xml&lt;/code&gt; a été généré, examinons son contenu :&lt;/p&gt;

&lt;pre class=&quot;xml&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;?xml&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;xliff&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;file&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;source-language&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;EN&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;target-language&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;datatype&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;plaintext&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;original&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;messages&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;date&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;2008-03-13T11:13:45Z&amp;quot;&lt;/span&gt;
    &lt;span style=&quot;color: #000066;&quot;&gt;product-name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;messages&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;body&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;trans&lt;/span&gt;-unit &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;source&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Contact us&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/source&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;target&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/target&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/trans&lt;/span&gt;-unit&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;trans&lt;/span&gt;-unit &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;2&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;source&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Drop us a message using the form below:&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/source&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;target&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/target&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/trans&lt;/span&gt;-unit&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;trans&lt;/span&gt;-unit &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;3&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;source&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Send your message&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/source&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;target&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/target&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/trans&lt;/span&gt;-unit&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/body&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/file&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/xliff&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il ne nous reste &lt;em&gt;plus qu'à&lt;/em&gt; traduire nos chaînes en remplissant les balises &lt;code&gt;&amp;lt;target&amp;gt;&amp;lt;/target&amp;gt;&lt;/code&gt; en conséquence pour traduire notre application en français. Si l'on venait à modifier notre template en supprimant, modifiant ou ajoutant de nouvelles chaînes, la tâche d'extraction se chargerait de mettre à jour nos fichiers de traduction en conséquence, tout en préservant le travail déjà effectué &lt;img src=&quot;/blog/themes/Puc4/smilies/smile.gif&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Symfony 1.1 beta, tour du propriétaire - Les formulaires</title>
    <link>http://prendreuncafe.com/blog/post/2008/03/11/Symfony-11-beta-tour-du-proprietaire-Les-formulaires</link>
    <guid isPermaLink="false">urn:md5:06e57c127e9ce12fd2905da7c9f68edc</guid>
    <pubDate>Tue, 11 Mar 2008 10:50:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>bestpractices</category><category>forms</category><category>framework</category><category>html</category><category>php</category><category>symfony</category><category>tutoriel</category>    
    <description>    &lt;p&gt;Nous venons de voir la &lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/Symfony-11-beta-tour-du-proprietaire-Installation&quot; hreflang=&quot;fr&quot;&gt;procédure d'installation de la beta1 de Symfony 1.1&lt;/a&gt;. Nous allons maintenant rentrer un peu plus dans les détails des nouvelles fonctionnalités en commençant par les formulaires.&lt;/p&gt;


&lt;h3&gt;La gestion des formulaires avec Symfony 1.1&lt;/h3&gt;


&lt;p&gt;La nouvelle gestion des formulaires est l'une des fonctionnalités majeures de cette nouvelle mouture du framework. Elle propose une séparation claire entre couche de contrôle, couche de définition et couche de présentation des données, soit un bon vieux pattern &lt;acronym title=&quot;Modèle Vue Contrôleur&quot;&gt;MVC&lt;/acronym&gt; des familles.&lt;/p&gt;


&lt;p&gt;Pour illustrer ces fonctionnalités, nous allons retrousser nos manches et créer un formulaire de contact basique. On commence par initialiser un nouveau module &lt;code&gt;contact&lt;/code&gt; dans l'application &lt;code&gt;main&lt;/code&gt; de notre projet &lt;code&gt;sf11test&lt;/code&gt; initié &lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/Symfony-11-beta-tour-du-proprietaire-Installation&quot; hreflang=&quot;fr&quot;&gt;précédemment&lt;/a&gt; :&lt;/p&gt;


&lt;pre&gt;$ ./symfony generate:module main contact&lt;/pre&gt;


&lt;h4&gt;Création d'une classe de formulaire&lt;/h4&gt;


&lt;p&gt;Nous allons créer une classe qui représentera notre formulaire de contact, que nous stockerons dans le fichier &lt;code&gt;apps/main/lib/ContactForm.class.php&lt;/code&gt;. Cette classe étendra la classe de base &lt;code&gt;sfForm&lt;/code&gt; et surchargera sa méthode de configuration afin de définir les champs de formulaire et les différents validateurs associés. Nous définirons quatre champs (appelés &lt;em&gt;widgets&lt;/em&gt; en Symfony 1.1) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Le nom de l'expéditeur, sous la forme d'un champs de saisie textuelle (&lt;code&gt;&amp;lt;input type=&amp;quot;text&amp;quot;/&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Son adresse email, également sous la forme d'un champs de saisie textuelle&lt;/li&gt;
&lt;li&gt;Le sujet de son message, sous la forme d'une boîte de sélection (&lt;code&gt;&amp;lt;select/&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Le texte de son message, sous la forme d'un champs texte multilignes (&lt;code&gt;&amp;lt;textarea/&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; ContactForm extends sfForm
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; configure&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Widgets&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$topics&lt;/span&gt; = sfConfig::&lt;span style=&quot;color: #006600;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'app_contact_topics'&lt;/span&gt;, &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$widgetSchema&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormSchema&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormSelect&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'choices'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$topics&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormTextarea&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$widgetSchema&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setNameFormat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'contact[%s]'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// HTML field names format&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setWidgetSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$widgetSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Validators&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setValidators&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorRegex&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'pattern'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'/[a-z_]/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'min_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,
                                               &lt;span style=&quot;color: #ff0000;&quot;&gt;'max_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorAnd&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorEmail&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
                                            &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'max_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'min_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Au passage, nous ajoutons les sujets possibles de message dans le fichier de configuration &lt;code&gt;apps/main/config/app.yml&lt;/code&gt; :&lt;/p&gt;

&lt;pre&gt;
all:
  contact:
    topics:
      carrots_request: Do you have carrots?
      eggs_request:    Do you have eggs?
&lt;/pre&gt;


&lt;p&gt;Marquons un arrêt pour examiner de plus près ce que nous venons d'écrire :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nous avons ajouté 4 &lt;em&gt;widgets&lt;/em&gt; à notre formulaires,&lt;/li&gt;
&lt;li&gt;Nous avons défini et paramétré leurs validateurs associés,
&lt;ul&gt;
&lt;li&gt;Au passage, vous noterez qu'il est possible de spécifier plusieurs validateurs pour un même champs, comme c'est ici le cas pour le champs &lt;code&gt;email&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Nous avons défini le format de nommage des champs de formulaire et choisi une syntaxe à base de tableau pour manipuler plus aisément les données dans notre action,&lt;/li&gt;
&lt;li&gt;Nous avons déporté une partie de la configuration textuelle dans un fichier externe dédié, pour en faciliter la maintenance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;N'oublions pas de purger le cache de Symfony, car nous venons d'ajouter un nouvel objet php :&lt;/p&gt;


&lt;pre&gt;$ ./symfony cc&lt;/pre&gt;


&lt;h4&gt;Interaction avec le formulaire depuis le contrôleur de l'application&lt;/h4&gt;


&lt;p&gt;Éditons maintenant le fichier &lt;code&gt;apps/main/modules/contact/actions/actions.class.php&lt;/code&gt; pour y définir l'action par défaut du module&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#pnote-948-1&quot; id=&quot;rev-pnote-948-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; contactActions extends sfActions
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeIndex&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;sfWebRequest &lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; ContactForm&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isMethod&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// If HTTP method is POST&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Bind submitted values to the contact form instance&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getParameter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'contact'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Validate the form&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; 
      &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Retrieve submitted values&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;$values&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getValues&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; 
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// ... Send your message here using submitted values&lt;/span&gt;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Then redirect user to the homepage with a one-shot message&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getUser&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Message sent'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'@homepage'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Publish form instance to the view&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;form&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Ici, dans l'ordre :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On instancie un objet de formulaire de contact&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Si&lt;/strong&gt; la méthode HTTP est POST :
&lt;ul&gt;
&lt;li&gt;On assigne les paramètres de la requête correspondant aux champs du formulaire de contact à ce dernier&lt;/li&gt;
&lt;li&gt;On lance la validation, et &lt;strong&gt;si&lt;/strong&gt; c'est valide :
&lt;ul&gt;
&lt;li&gt;On effectue les opérations nécessaires (traitement, redirection, etc.)&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vous noterez que tous les &lt;em&gt;sinon&lt;/em&gt; sont gérés automatiquement par le framework de façon transparente (mais ces comportements par défaut sont toujours surchargeables) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Par défaut le formulaire présenté sera vierge&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#pnote-948-2&quot; id=&quot;rev-pnote-948-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;,&lt;/li&gt;
&lt;li&gt;Les champs seront  automatiquement préremplis en cas d'erreur de validation,&lt;/li&gt;
&lt;li&gt;Les erreurs seront contextualisées par rapport aux champs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Rendu du formulaire dans la vue&lt;/h4&gt;


&lt;p&gt;Enfin, il nous reste à créer un template pour présenter le formulaire et éventuellement afficher un message à l'utilisateur, dans notre vue gérée au travers du fichier &lt;code&gt;apps/main/modules/contact/templates/indexSuccess.php&lt;/code&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sf_user&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;hasFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;p &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;notice&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$sf_user&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/p&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;endif&lt;/span&gt;; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
&amp;nbsp;
&amp;lt;form action=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;?php echo url_for('contact/index') ?&amp;gt;&amp;quot;&lt;/span&gt; method=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&amp;gt;
  &amp;lt;table&amp;gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;input type=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; /&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;
&amp;lt;/form&amp;gt;&lt;/pre&gt;


&lt;p&gt;Si on charge la page &lt;code&gt;/main_dev.php/contact&lt;/code&gt;, on a le résultat suivant :&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/ScreenShots/Symfony/sf11test_form.png&quot; alt=&quot;Symfony 1.1 test form&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Au passage si vous regardez la source, une protection anti &lt;a href=&quot;http://fr.wikipedia.org/wiki/Cross-Site_Request_Forgeries&quot; hreflang=&quot;fr&quot;&gt;CSRF&lt;/a&gt; est automatiquement gérée de façon transparente.&lt;/p&gt;


&lt;p&gt;Bien entendu, le mode de rendu par défaut utilise un tableau pour la mise en forme, mais il existe un autre décorateur plus &lt;em&gt;sémantique&lt;/em&gt; à base de liste. Pour l'utiliser, modifions notre classe &lt;code&gt;ContactForm&lt;/code&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; ContactForm extends sfForm
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; configure&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
   &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// ...&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;widgetSchema&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setFormFormatterName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'list'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Il conviendra bien entendu d'adapter le template pour enlever les balises tables. On peut aussi imaginer de créer notre propre décorateur HTML. Par exemple, créeons la classe &lt;code&gt;sfWidgetFormSchemaFormatterDiv&lt;/code&gt; comme suit :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; sfWidgetFormSchemaFormatterDiv extends sfWidgetFormSchemaFormatter
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  protected
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$rowFormat&lt;/span&gt;       = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;div class=&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;form-row&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;&amp;gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;  %error%%label%&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;  %field%%help%&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;%hidden_fields%&amp;lt;/div&amp;gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;,
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$errorRowFormat&lt;/span&gt;  = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;div class=&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;form-errors&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\&amp;quot;&lt;/span&gt;&amp;gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;%errors%&amp;lt;/div&amp;gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;,
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$helpFormat&lt;/span&gt;      = &lt;span style=&quot;color: #ff0000;&quot;&gt;'&amp;lt;div class=&amp;quot;form-help&amp;quot;&amp;gt;%help%&amp;lt;/div&amp;gt;'&lt;/span&gt;,
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$decoratorFormat&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;div&amp;gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;  %content%&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Encore une fois, modifions notre classe &lt;code&gt;ContactForm&lt;/code&gt; pour l'utiliser (après avoir purgé le cache symfony, comme il se doit) :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; ContactForm extends sfForm
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; configure&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
   &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// ...&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;widgetSchema&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setFormFormatterName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'div'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;Rendu des widgets&lt;/h4&gt;


&lt;p&gt;Vous me direz, un simple &lt;code&gt;&amp;lt;?php echo $form ?&amp;gt;&lt;/code&gt; n'est pas très satisfaisant du point de vue de l'intégration HTML, qui nécessite bien souvent de prendre la main finement sur le code html généré. Le framework de formulaires de Symfony 1.1 apporte une solution en permettant de générer le rendu de chacun des widgets de façon indépendante&lt;/p&gt;


&lt;p&gt;Imaginons par exemple que nous souhaitions gérer spécifiquement la présentation du champ &lt;code&gt;name&lt;/code&gt; de notre formulaire ; notre template devient alors :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sf_user&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;hasFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;p &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;notice&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$sf_user&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/p&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;endif&lt;/span&gt;; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
&amp;nbsp;
&amp;lt;form action=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;lt;?php echo url_for('contact/index') ?&amp;gt;&amp;quot;&lt;/span&gt; method=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&amp;gt;
  &amp;lt;table&amp;gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;renderRow&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;th&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;renderLabel&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/th&amp;gt;
      &amp;lt;td&amp;gt;
        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;renderError&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'class'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'toto'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
      &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;renderRow&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;renderRow&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;input type=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; /&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;
&amp;lt;/form&amp;gt;&lt;/pre&gt;


&lt;p&gt;Vous noterez qu'on accède ici aux différents widgets du formulaire au moyen de clés de tableaux classiques ; c'est tout simplement car la classe &lt;code&gt;sfForm&lt;/code&gt; implémente l'interface &lt;code&gt;&lt;a href=&quot;http://www.php.net/~helly/php/ext/spl/interfaceArrayAccess.html&quot; hreflang=&quot;en&quot;&gt;ArrayAccess&lt;/a&gt;&lt;/code&gt; de la &lt;a href=&quot;http://www.php.net/~helly/php/ext/spl/&quot; hreflang=&quot;en&quot;&gt;SPL&lt;/a&gt;. C'est très pratique !&lt;/p&gt;


&lt;h4&gt;Le nerf de la guerre : la génération de formulaires à partir d'objets Propel&lt;/h4&gt;


&lt;p&gt;Ayant été à une lointaine époque un fervent adepte de &lt;a href=&quot;http://pear.php.net/package/DB_DataObject_FormBuilder&quot; hreflang=&quot;en&quot;&gt;PEAR::FormBuilder&lt;/a&gt;, brique permettant de générer des formulaires à partir d'instance d'objets de données &lt;acronym title=&quot;Object Relational Mapping&quot;&gt;ORM&lt;/acronym&gt;, j'étais curieux de voir comment cette fonctionnalité demandée par les développeurs depuis longtemps allait être implémentée dans Symfony 1.1 au travers de l'ORM &lt;a href=&quot;http://propel.phpdb.org/&quot; hreflang=&quot;en&quot;&gt;Propel&lt;/a&gt;, bundlé par défaut&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#pnote-948-3&quot; id=&quot;rev-pnote-948-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;Après avoir configuré un accès à notre &lt;acronym title=&quot;Système de Gestion de Bases de Données&quot;&gt;SGBD&lt;/acronym&gt; préféré&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#pnote-948-4&quot; id=&quot;rev-pnote-948-4&quot;&gt;4&lt;/a&gt;]&lt;/sup&gt;, nous allons définir une table &lt;code&gt;contact_demand&lt;/code&gt; dans notre fichier &lt;code&gt;config/schema.yml&lt;/code&gt; pour y stoker nos demandes de contacts :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;propel:
  contact_demand:
    id:
    name:    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; type: varchar, size: &lt;span style=&quot;color: #cc66cc;&quot;&gt;45&lt;/span&gt;, required: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    email:   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; type: varchar, size: &lt;span style=&quot;color: #cc66cc;&quot;&gt;100&lt;/span&gt;, required: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    topic:   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; type: varchar, size: &lt;span style=&quot;color: #cc66cc;&quot;&gt;255&lt;/span&gt;, required: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    message: &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; type: longvarchar, required: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    created_at:&lt;/pre&gt;


&lt;p&gt;On lance rapidement la tâche de création de la table et des objets ORM associés :&lt;/p&gt;


&lt;pre&gt;$ ./symfony propel:build-all
$ ./symfony cc&lt;/pre&gt;


&lt;p&gt;Maintenant, allons faire un tour dans le répertoire &lt;code&gt;lib/model&lt;/code&gt; pour voir ce qui a été généré. Surprise, des objets de formulaires ont été automatiquement créés pour nous !&lt;/p&gt;


&lt;p&gt;Jetons un oeil plus particulièrement au fichier &lt;code&gt;lib/form/base/BaseContactDemandForm.class.php&lt;/code&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; BaseContactDemandForm extends BaseFormPropel
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; setup&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setWidgets&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;         =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInputHidden&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;       =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormTextarea&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'created_at'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormDateTime&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setValidators&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;         =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorPropelChoice&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'model'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'ContactDemand'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'column'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Id'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'required'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;       =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'created_at'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorDateTime&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'required'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;widgetSchema&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setNameFormat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'contact_demand[%s]'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;errorSchema&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorErrorSchema&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;validatorSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    parent::&lt;span style=&quot;color: #006600;&quot;&gt;setup&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; getModelName&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'ContactDemand'&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Cela ne vous rappelle rien ? C'est presque quasiment ce que nous avions écrit manuellement précédemment dans notre classe &lt;code&gt;ContactForm&lt;/code&gt;. On notera également la présence dans le fichier &lt;code&gt;lib/form/ContactDemandForm.class.php&lt;/code&gt; de la classe &lt;code&gt;ContactDemandForm&lt;/code&gt;, cette dernière héritant de &lt;code&gt;BaseContactDemandForm.class.php&lt;/code&gt;, ce qui nous permettra de surcharger tout ou partie de ses méthodes pour adapter le formulaire généré à nos besoins.&lt;/p&gt;


&lt;p&gt;En l'occurrence, il nous faut adapter un peu la méthode &lt;code&gt;configure()&lt;/code&gt; pour retrouver notre &lt;em&gt;sélecteur de sujets&lt;/em&gt; et réappliquer nos validateurs. Voici le code de la classe &lt;code&gt;ContactDemandForm&lt;/code&gt; modifiée en conséquence :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; ContactDemandForm extends BaseContactDemandForm
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; configure&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Widgets&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$topics&lt;/span&gt; = sfConfig::&lt;span style=&quot;color: #006600;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'app_contact_topics'&lt;/span&gt;, &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setWidgets&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInputHidden&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormSelect&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'choices'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$topics&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInput&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormTextarea&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Validators&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setValidators&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;         =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorPropelChoice&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'model'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'ContactDemand'&lt;/span&gt;,
                                                        &lt;span style=&quot;color: #ff0000;&quot;&gt;'column'&lt;/span&gt;   =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Id'&lt;/span&gt;,
                                                        &lt;span style=&quot;color: #ff0000;&quot;&gt;'required'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'topic'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorRegex&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'pattern'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'/[a-z_]/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'name'&lt;/span&gt;       =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'min_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,
                                                  &lt;span style=&quot;color: #ff0000;&quot;&gt;'max_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;      =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorAnd&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorEmail&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
                                               &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'max_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'message'&lt;/span&gt;    =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'min_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
      &lt;span style=&quot;color: #ff0000;&quot;&gt;'created_at'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorDateTime&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'required'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;widgetSchema&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setNameFormat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'contact_demand[%s]'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;errorSchema&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorErrorSchema&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;validatorSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;On va maintenant modifier notre action pour prendre en compte notre nouvelle classe de formulaire liée à notre objet Propel :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; contactActions extends sfActions
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeIndex&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;sfWebRequest &lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; ContactDemandForm&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isMethod&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// If HTTP method is POST&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Bind submitted values to the contact form instance&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getParameter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'contact_demand'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Validate the form&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isValid&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
      &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Save submitted values in form's ContactDemand object&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;save&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Then redirect user to the homepage with a one-shot message&lt;/span&gt;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getUser&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Message sent'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
        &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'@homepage'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Publish form instance to the view&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;form&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Ainsi, un simple &lt;code&gt;$form-&amp;gt;save()&lt;/code&gt; nous permet de persister en base les données soumises par l'utilisateur au travers du formulaire autogénéré. Un sacré gain de productivité en phase de prototypage, assurement !&lt;/p&gt;


&lt;h4&gt;En conclusion&lt;/h4&gt;


&lt;p&gt;Voilà, ce n'est bien évidemment là qu'une infime partie de ce que peut faire le nouveau système de gestion de formulaires de Symfony 1.1, mais c'est un peu à reculons que l'on retourne à l'ancien système &lt;img src=&quot;/blog/themes/Puc4/smilies/wink.gif&quot; alt=&quot;;-)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#rev-pnote-948-1&quot; id=&quot;pnote-948-1&quot;&gt;1&lt;/a&gt;] Nous ne créons pas de route pour le moment, même si ce serait là une bonne pratique, afin de ne pas surcharger inutilement le contenu de ce tutorial, déjà bien assez dense comme ça &lt;img src=&quot;/blog/themes/Puc4/smilies/smile.gif&quot; alt=&quot;:-)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#rev-pnote-948-2&quot; id=&quot;pnote-948-2&quot;&gt;2&lt;/a&gt;] On aurait bien entendu pu proposer des valeurs par défaut.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#rev-pnote-948-3&quot; id=&quot;pnote-948-3&quot;&gt;3&lt;/a&gt;] Le mécanisme de génération de code devrait permettre de proposer facilement la même fonctionnalité pour Doctrine prochainement.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/11/#rev-pnote-948-4&quot; id=&quot;pnote-948-4&quot;&gt;4&lt;/a&gt;] Je vous laisse le soin de vous référer au &lt;a href=&quot;http://prendreuncafe.com/blog/post/2007/04/28/Gagnez-du-temps-avec-Symfony-et-son-generateur-de-back-office&quot; hreflang=&quot;fr&quot;&gt;tutoriel existant&lt;/a&gt; sur ce même blog &lt;img src=&quot;/blog/themes/Puc4/smilies/wink.gif&quot; alt=&quot;;-)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Symfony, une redirection 302 et une exception sont dans un bateau</title>
    <link>http://prendreuncafe.com/blog/post/2008/01/12/Symfony-une-redirection-302-et-une-exception-sont-dans-un-bateau</link>
    <guid isPermaLink="false">urn:md5:5351e7d789b0a5e75088fbee0c7270cd</guid>
    <pubDate>Sat, 12 Jan 2008 20:56:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>bestpractices</category><category>exceptions</category><category>php</category><category>symfony</category>    
    <description>    &lt;p&gt;Ah la la. C'est assez rare pour être souligné, mais je viens de me battre avec &lt;a href=&quot;http://www.symfony-project.com&quot; hreflang=&quot;en&quot;&gt;Symfony&lt;/a&gt; pendant près de deux heures avec un problème assez déroutant de prime abord : lorsque dans une action vous faites quelque chose d'aussi anodin que ceci :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeBar&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    try
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Some stuff here, if successful redirect user to somewhere else&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Action was successful'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'@whatever_route'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    catch &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Exception &lt;span style=&quot;color: #0000ff;&quot;&gt;$e&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
       &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getRequest&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setError&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'errors'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Something has failed somewhere, sorry dude'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
       &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;logMessage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Big boo boo occured: '&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$e&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getMessage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'err'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
       &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; sfView::&lt;span style=&quot;color: #006600;&quot;&gt;SUCCESS&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Et bien dans ce cas là, la redirection s'opère MAIS l'ensemble du rendu sera tout de même produit et envoyé au navigateur &lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/01/12/#pnote-937-1&quot; id=&quot;rev-pnote-937-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt; - ce qui peut s'avérer très couteux sur un site internet au final &lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/01/12/#pnote-937-2&quot; id=&quot;rev-pnote-937-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;. La raison en est très simple, la méthode &lt;code&gt;redirect()&lt;/code&gt; de la classe &lt;code&gt;sfActions&lt;/code&gt; met fin à l'execution par ce moyen &lt;a href=&quot;http://www.symfony-project.org/api/1_0/sfAction#method_redirect&quot; hreflang=&quot;en&quot;&gt;que l'on peut qualifier de hardi&lt;/a&gt; :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; redirect&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$url&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$statusCode&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;302&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$url&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getController&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;genUrl&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$url&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;sfConfig::&lt;span style=&quot;color: #006600;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'sf_logging_enabled'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getContext&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getLogger&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'{sfAction} redirect to &amp;quot;'&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$url&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;'&amp;quot;'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getController&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$url&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$statusCode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    throw &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfStopException&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Oui, vous avez bien lu, on interrompt le script en levant une exception, ici de type &lt;code&gt;&lt;a href=&quot;http://www.symfony-project.org/api/1_0/sfStopException&quot; hreflang=&quot;en&quot;&gt;sfStopException&lt;/a&gt;&lt;/code&gt;. Le problème, c'est que dans mon exemple précédent, la méthode redirect() est appellée dans un bloc &lt;code&gt;try { } catch { }&lt;/code&gt;, et donc l'exception levée est interceptée et l'action n'est au final pas stoppée. Vicieux, hein ?&lt;/p&gt;


&lt;p&gt;Pour régler le problème, on peut par exemple toujours effectuer ses appels à la méthode &lt;code&gt;redirect()&lt;/code&gt; en dehors d'un block &lt;code&gt;try { } catch { }&lt;/code&gt; &lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/01/12/#pnote-937-3&quot; id=&quot;rev-pnote-937-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;, ou encore tester le type de l'exception levée. Dans notre exemple, cette dernière solution ressemblerait à ça :&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeFoo&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    try
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Some stuff here, if successful redirect user to somewhere else&lt;/span&gt;
      &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/// ...&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setFlash&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'notice'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Action was successful'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'@whatever_route'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    catch &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;sfStopException &lt;span style=&quot;color: #0000ff;&quot;&gt;$e&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; sfView::&lt;span style=&quot;color: #006600;&quot;&gt;HEADER_ONLY&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
    catch &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Exception &lt;span style=&quot;color: #0000ff;&quot;&gt;$e&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getRequest&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setError&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'errors'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Something has failed somewhere, sorry dude'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;logMessage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Big boo boo occured: '&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$e&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getMessage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'err'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; sfView::&lt;span style=&quot;color: #006600;&quot;&gt;SUCCESS&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;C'est pas super sexy, mais ça fonctionne, et ça a le mérite de m'inspirer deux morales à cette histoire :&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;tester le type des exceptions que l'on catche, c'est bien&lt;/li&gt;
&lt;li&gt;lever une exception pour arrêter un script, c'est super cracra et mériterait éventuellement d'être patché &lt;img src=&quot;/blog/themes/Puc4/smilies/wink.gif&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Edit: &lt;/strong&gt; Je m'exprime mal, c'est pas &lt;em&gt;super cracra&lt;/em&gt;, c'est juste que ça introduit une petite complexité supplémentaire. Mais l'utilité de la chose est bien entendu totalement avérée si on a besoin d'effectuer des opérations particulières avant la fin du script ( ce qui est rarement le cas, enfin chez moi).&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/01/12/#rev-pnote-937-1&quot; id=&quot;pnote-937-1&quot;&gt;1&lt;/a&gt;] Avec tout ce que ça comporte de requête SQL et de templates calculés &lt;em&gt;pour rien&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/01/12/#rev-pnote-937-2&quot; id=&quot;pnote-937-2&quot;&gt;2&lt;/a&gt;] Et oui bien sûr, faire un &lt;code&gt;redirect()&lt;/code&gt; dans un bloc &lt;code&gt;try catch&lt;/code&gt; c'est pas forcément le meilleur endroit, mais c'est teeeellement pratique &lt;img src=&quot;/blog/themes/Puc4/smilies/tongue.gif&quot; alt=&quot;:p&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/01/12/#rev-pnote-937-3&quot; id=&quot;pnote-937-3&quot;&gt;3&lt;/a&gt;] Qui sera donc exécuté de toute façon si aucune exception n'est levée.&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>A new Django freelance in town</title>
    <link>http://prendreuncafe.com/blog/post/2007/11/05/A-new-Django-freelance-in-town</link>
    <guid isPermaLink="false">urn:md5:03323047c64b11f51fc2c342ce7c70f8</guid>
    <pubDate>Mon, 05 Nov 2007 21:33:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Divers</category>
        <category>bestpractices</category><category>django</category><category>freelance</category><category>python</category>    
    <description>    &lt;p&gt;Il est suffisamment rare de rencontrer un &lt;a href=&quot;http://welldev.fr/&quot; hreflang=&quot;fr&quot;&gt;passionné du web&lt;/a&gt; comme &lt;a href=&quot;http://david.larlet.fr/&quot; hreflang=&quot;fr&quot;&gt;David Larlet&lt;/a&gt; pour se priver du luxe de lui faire un peu de pub quand il décide de &lt;a href=&quot;http://www.biologeek.com/journal/index.php/freelance-django-enfin-independant&quot; hreflang=&quot;fr&quot;&gt;se mettre à son compte&lt;/a&gt; &lt;img src=&quot;/blog/themes/Puc4/smilies/smile.gif&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Dont acte, si vous désirez confier la conception et la réalisation de votre projet web à un professionnel amoureux des standards et bonnes pratiques du web et prompt à s'impliquer à vos côtés dans toutes les phases de l'accompagnement de votre projet, je vous engage à &lt;a href=&quot;http://welldev.fr/#contact&quot; hreflang=&quot;fr&quot;&gt;prendre contact avec lui&lt;/a&gt; de ce pas.&lt;/p&gt;</description>
    
    
    
      </item>
    
</channel>
</rss>