<?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/">
<channel>
  <title>Prendre un Café - tutoriel</title>
  <link>http://prendreuncafe.com/blog/</link>
  <description></description>
  <language>fr</language>
  <pubDate>Wed, 14 May 2008 15:57:49 +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>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 1.1 beta, tour du propriétaire - Installation</title>
    <link>http://prendreuncafe.com/blog/post/2008/03/10/Symfony-11-beta-tour-du-proprietaire-Installation</link>
    <guid isPermaLink="false">urn:md5:62e5af261ac4dbd24757d85e20f67b67</guid>
    <pubDate>Mon, 10 Mar 2008 16:10:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>framework</category><category>php</category><category>symfony</category><category>tutoriel</category>    
    <description>    &lt;p&gt;Il y a quelques jours, &lt;a href=&quot;http://www.aide-de-camp.org/&quot; hreflang=&quot;fr&quot;&gt;Fabien&lt;/a&gt; a annoncé la &lt;a href=&quot;http://www.symfony-project.org/blog/2008/02/26/last-major-change-for-symfony-1-1&quot; hreflang=&quot;en&quot;&gt;disponibilité de Symfony 1.1 beta 1&lt;/a&gt; dans le dépôt du projet. Symfony 1.1 est un changement majeur au niveau architecture, et la compatibilité ascendante est rompue en de nombreux points. Pour un outil éminemment basé sur les conventions, cela implique une réappropriation de ces dernières quand elles ont changé - mais c'est là le prix à payer pour bénéficier des nouvelles fonctionnalités. Et elles valent le coup !&lt;/p&gt;


&lt;p&gt;Ce billet sera donc le premier d'une série destinée à explorer les fonctionnalités phares de cette preversion. On commence par le commencement avec la procédure d'installation.&lt;/p&gt;


&lt;h3&gt;Remarques préliminaires&lt;/h3&gt;


&lt;p&gt;Nous ne verrons pas la procédure de mise à jour d'un projet en symfony 1.0 vers la version 1.1&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#pnote-947-1&quot; id=&quot;rev-pnote-947-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;. On verra ça plus en détail sur ce blog si les &lt;acronym title=&quot;Conditions Normales de Température et de Pression&quot;&gt;CNTP&lt;/acronym&gt; le permettent. Pour l'heure, on partira donc d'un projet vierge en 1.1.&lt;/p&gt;


&lt;h3&gt;Installation de Symfony 1.1&lt;/h3&gt;


&lt;p&gt;Il faut pour l'heure installer Symfony 1.1 à partir des sources subversion ; voici une démarche possible, en admettant que vous disposez d'un environnement Unix/Linux&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#pnote-947-2&quot; id=&quot;rev-pnote-947-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt; :&lt;/p&gt;


&lt;pre&gt;$ mkdir vendor &amp;amp;&amp;amp; cd vendor
$ svn co http://svn.symfony-project.com/branches/1.1/ symfony11
$ sudo ln -s `pwd`/symfony11/data/bin/symfony /usr/bin/symfony11&lt;/pre&gt;


&lt;p&gt;Je crée ici un lien symbolique &lt;code&gt;symfony11&lt;/code&gt; accessible depuis &lt;code&gt;/usr/bin&lt;/code&gt;, ce qui permettra de gérer aussi bien des projets en 1.0 qu'en 1.1&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#pnote-947-3&quot; id=&quot;rev-pnote-947-3&quot;&gt;3&lt;/a&gt;]&lt;/sup&gt;.&lt;/p&gt;


&lt;p&gt;Pour vérifier que tout s'est bien déroulé, vous pouvez lancer cette commande :&lt;/p&gt;


&lt;pre&gt;$ symfony11 -V
symfony version 1.1.0-DEV (/Users/niko/www/vendor/symfony11/lib)&lt;/pre&gt;


&lt;h3&gt;Création d'un nouveau projet&lt;/h3&gt;


&lt;p&gt;Grâce à notre nouvelle installation isolée de Symfony 1.1, on peut créer un projet et une nouvelle application &lt;code&gt;main&lt;/code&gt; via cette série de commandes :&lt;/p&gt;


&lt;pre&gt;$ cd /path/to/workspace
$ mkdir sf11test &amp;amp;&amp;amp; cd sf11test
$ symfony11 generate:project sf11test
$ ./symfony generate:app main&lt;/pre&gt;


&lt;p&gt;Vous noterez que toutes les commandes ont été renommées par rapport à la version 1.0 et qu'elles utilisent désormais des espaces de noms spécifiques à certains domaines : &lt;code&gt;generate:&lt;/code&gt;, &lt;code&gt;propel:&lt;/code&gt;, &lt;code&gt;plugins:&lt;/code&gt;, &lt;code&gt;log:&lt;/code&gt;, etc. Pour lister l'ensemble des tâches en lignes de commande disponibles, vous pouvez lancer la commande &lt;code&gt;symfony11&lt;/code&gt; telle quelle, ou utiliser l'executable &lt;code&gt;symfony&lt;/code&gt; disponible à la racine de votre projet :&lt;/p&gt;


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


&lt;p&gt;Notez que l'emploi de &lt;code&gt;symfony11&lt;/code&gt; ou &lt;code&gt;./symfony&lt;/code&gt; a la racine de votre projet ont ici strictement le même effet, puisque les deux exécutables référencent la même installation de Symfony.&lt;/p&gt;


&lt;p&gt;Il nous reste à créer un VHost Apache&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#pnote-947-4&quot; id=&quot;rev-pnote-947-4&quot;&gt;4&lt;/a&gt;]&lt;/sup&gt; minimaliste pour accéder à notre projet au travers de notre navigateur :&lt;/p&gt;


&lt;pre&gt;&amp;lt;VirtualHost *&amp;gt;
  ServerName   local.sf11test.org
  DocumentRoot %PROJECT_ROOT%/web
  &amp;lt;Directory &amp;quot;%PROJECT_ROOT%/web&amp;quot;&amp;gt;
    AllowOverride All 
    Allow from All 
  &amp;lt;/Directory&amp;gt;
  Alias /sf    %VENDOR_ROOT%/symfony11/data/web/sf
  ErrorLog     %PROJECT_ROOT%/log/error.log
  CustomLog    %PROJECT_ROOT%/log/access.log common
&amp;lt;/VirtualHost&amp;gt;&lt;/pre&gt;


&lt;p&gt;N'oubliez pas de remplacer les chaînes &lt;code&gt;%PROJECT_ROOT%&lt;/code&gt; et &lt;code&gt;%VENDOR_ROOT%&lt;/code&gt; par les chemins système correspondant (respectivement la racine du projet et la racine de votre répertoire &lt;code&gt;vendor&lt;/code&gt; créé précédemment).&lt;/p&gt;


&lt;p&gt;On ajoutera également une entrée dans le fichier &lt;code&gt;/etc/hosts&lt;/code&gt; pour avoir la résolution du nom &lt;code&gt;local.sf11test.org&lt;/code&gt; localement :&lt;/p&gt;


&lt;pre&gt;127.0.0.1       local.sf11test.org&lt;/pre&gt;


&lt;p&gt;Si toutes les étapes ont été correctement suivies et après avoir rechargé la configuration d'Apache, en lançant notre navigateur préféré sur l'adresse &lt;code&gt;local.sf11test.org&lt;/code&gt;, nous obtenons :&lt;/p&gt;


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


&lt;p&gt;Ça vous rappelle quelque chose ? &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;La suite au prochain épisode, avec les formulaires dont la gestion a été entièrement revue en Symfony 1.1.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Edit :&lt;/strong&gt; J'ai modifié l'url du dépôt pour faire pointer vers la branche 1.1, qui évolue constamment, comme suggéré par Fabien en commentaire &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;Pour ceux qui veulent mettre à jour du tag vers la branche, il faut lancer cette commande à la racine de votre répertoire &lt;code&gt;vendor&lt;/code&gt; :&lt;/p&gt;


&lt;pre&gt;$ svn switch http://svn.symfony-project.com/branches/1.1/ symfony11&lt;/pre&gt;


&lt;p&gt;Un petit &lt;code&gt;./symfony cc&lt;/code&gt; s'imposera dans vos projets utilisant le dépôt.&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/10/#rev-pnote-947-1&quot; id=&quot;pnote-947-1&quot;&gt;1&lt;/a&gt;] La procédure est pour le moment documenté dans &lt;a href=&quot;http://svn.symfony-project.com/branches/1.1/UPGRADE&quot; hreflang=&quot;en&quot;&gt;ce fichier sur le dépôt&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#rev-pnote-947-2&quot; id=&quot;pnote-947-2&quot;&gt;2&lt;/a&gt;] Enfin je veux dire, je ne m'occuperai pas de Windows &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;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#rev-pnote-947-3&quot; id=&quot;pnote-947-3&quot;&gt;3&lt;/a&gt;] En admettant bien sûr que vous disposiez déjà d'une installation fonctionnelle de la 1.0 &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;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/03/10/#rev-pnote-947-4&quot; id=&quot;pnote-947-4&quot;&gt;4&lt;/a&gt;] Comme toujours, &lt;code&gt;mod_rewrite&lt;/code&gt; doit être activé.&lt;/p&gt;&lt;/div&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Symfony, Admin-Generator et Composants</title>
    <link>http://prendreuncafe.com/blog/post/2007/04/29/Symfony-Admin-Generator-et-Composants</link>
    <guid isPermaLink="false">urn:md5:37a31fd46938fbb80c8daf194352462e</guid>
    <pubDate>Sun, 29 Apr 2007 15:15:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>bestpractices</category><category>framework</category><category>php</category><category>symfony</category><category>tutoriel</category>    
    <description>    &lt;p&gt;Dans un précédent billet, nous avons vu comment &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;créer un weblog basique avec l'admin-generator de Symfony&lt;/a&gt;. Nous allons reprendre là où nous en étions et ajouter la liste des commentaires à notre back-office de gestion des billets grâce à un simple appel de composant, qui n'est autre qu'un &lt;a href=&quot;http://www.symfony-project.com/book/trunk/07-Inside-the-View-Layer#Partials&quot; hreflang=&quot;en&quot;&gt;template partiel&lt;/a&gt; associé à un contrôleur dédié.&lt;/p&gt;


&lt;h3&gt;Création du module de gestion des commentaires en back-office&lt;/h3&gt;


&lt;p&gt;Si ce n'est déjà fait, on crée notre module de gestion des commentaires&lt;/p&gt;


&lt;pre&gt;# symfony propel-init-admin back comments Comment&lt;/pre&gt;


&lt;h3&gt;Création du composant qui va lister les commentaires d'un billet&lt;/h3&gt;


&lt;p&gt;Bien. On va maintenant créer un composant &lt;code&gt;postcomments&lt;/code&gt; qui affichera la liste des commentaires associés à un objet &lt;code&gt;Post&lt;/code&gt;, en créant un nouveau fichier &lt;code&gt;apps/back/modules/posts/actions/components.class.php&lt;/code&gt; et en y insérent le contenu ci-dessous :&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; postsComponents extends sfComponents 
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  
  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**
   * List comments for a given Post
   * 
   */&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executePostcomments&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;$post_id&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;getRequestParameter&lt;/span&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;&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;a href=&quot;http://www.php.net/is_null&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_null&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$post_id&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;$c&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Criteria&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: #0000ff;&quot;&gt;$c&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;CommentPeer::&lt;span style=&quot;color: #006600;&quot;&gt;POST_ID&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$post_id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$c&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;addDescendingOrderByColumn&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;CommentPeer::&lt;span style=&quot;color: #006600;&quot;&gt;CREATED_AT&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;comments&lt;/span&gt; = CommentPeer::&lt;span style=&quot;color: #006600;&quot;&gt;doSelect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$c&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: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;On crée maintenant le template partiel associé au contrôleur, dans le fichier &lt;code&gt;apps/back/modules/posts/templates/_postcomments.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;a href=&quot;http://www.php.net/isset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comments&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;
  &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;a href=&quot;http://www.php.net/count&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;count&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comments&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&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; use_helper&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Comment'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'Text'&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;dl&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;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comments&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&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;dt&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;a href=&quot;http://www.php.net/sprintf&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;sprintf&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;'Posté le &amp;lt;strong&amp;gt;%s&amp;lt;/strong&amp;gt; par &amp;lt;strong&amp;gt;%s&amp;lt;/strong&amp;gt; :'&lt;/span&gt;, 
                           format_date&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getCreatedAt&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;'d/MM/yyyy à H:m'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,
                           format_comment_author&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getAuthor&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: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getSite&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;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
      &amp;lt;/dt&amp;gt;
      &amp;lt;dd&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; simple_format_text&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getContent&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: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
      &amp;lt;/dd&amp;gt;
      &amp;lt;dd&amp;gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&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; link_to&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Éditer'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'comments/edit?id='&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getId&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: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
        &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&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; link_to&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'Supprimer'&lt;/span&gt;, 
                            &lt;span style=&quot;color: #ff0000;&quot;&gt;'comments/delete?id='&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getId&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;'confirm=Êtes-vous sûr ?'&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: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;
      &amp;lt;/dd&amp;gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; endforeach; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;/dl&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;else&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;p&amp;gt;No comment yet.&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;
&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;&lt;/pre&gt;


&lt;h4&gt;Utilisation d'un &lt;em&gt;helper&lt;/em&gt; pour des tâches courantes de templating&lt;/h4&gt;


&lt;p&gt;La fonction &lt;code&gt;format_comment_author&lt;/code&gt; est un &lt;em&gt;helper&lt;/em&gt; maison, que nous définissons dans un  nouveau fichier &lt;code&gt;lib/helper/CommentHelper.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: #808080; font-style: italic;&quot;&gt;/**
 * Returns a formatted html string for author including website link if any
 * 
 * @param  string   $name
 * @param  string   $site
 * @param  boolean  $nofollow
 * @return string 
 */&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; format_comment_author&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$name&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$site&lt;/span&gt;=&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$nofollow&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: #66cc66;&quot;&gt;&amp;#123;&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;a href=&quot;http://www.php.net/is_null&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_null&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$site&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;amp;&amp;amp; &lt;a href=&quot;http://www.php.net/preg_match&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match&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;'/^http/i'&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$site&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: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;a href=&quot;http://www.php.net/sprintf&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;sprintf&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;'&amp;lt;a href=&amp;quot;%s&amp;quot;%s&amp;gt;%s&amp;lt;/a&amp;gt;'&lt;/span&gt;, 
                   &lt;span style=&quot;color: #0000ff;&quot;&gt;$site&lt;/span&gt;, 
                   &lt;span style=&quot;color: #0000ff;&quot;&gt;$nofollow&lt;/span&gt; === &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt; ? &lt;span style=&quot;color: #ff0000;&quot;&gt;' rel=&amp;quot;nofollow&amp;quot;'&lt;/span&gt; : &lt;span style=&quot;color: #ff0000;&quot;&gt;''&lt;/span&gt;,
                   &lt;span style=&quot;color: #0000ff;&quot;&gt;$name&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: #b1b100;&quot;&gt;else&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: #0000ff;&quot;&gt;$name&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;h3&gt;Mise à jour du back-office de gestion des billets&lt;/h3&gt;


&lt;p&gt;Ceci fait, modifions le fichier de configuration du back-office d'administration des billets créé &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;précemment&lt;/a&gt; et situé dans le fichier &lt;code&gt;apps/back/modules/posts/config/generator.yml&lt;/code&gt;, afin d'appeller notre nouveau composant &lt;code&gt;postcomments&lt;/code&gt; pour la vue d'édition d'un billet :&lt;/p&gt;

&lt;pre&gt;
  [...]

    # Customisation du formulaire d'ajout/édition
    edit:
      
      [...]

      # Affichage d'une sélection de champs
      display:         [author_id, title, excerpt, body, post_sections, ~postcomments]
&lt;/pre&gt;


&lt;p&gt;Vous noterez le caractère &lt;strong&gt;&lt;code&gt;~&lt;/code&gt;&lt;/strong&gt; précedant le nom du composant : encore une convention Symfony qui nous simplifie la vie &lt;img src=&quot;/blog/themes/PuC4/smilies/smile.gif&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;Gestion de l'échappement&lt;/h3&gt;


&lt;p&gt;Vous avez tous déjà entendu parler des failles  &lt;a href=&quot;http://fr.wikipedia.org/wiki/Cross_site_scripting&quot; hreflang=&quot;fr&quot;&gt;XSS&lt;/a&gt; ? Pour nous en prémunir partiellement, nous allons activer l'échappement automatique des contenus passés à une vue, en ajoutant ces directives dans le fichier &lt;code&gt;apps/back/config/settings.yml&lt;/code&gt; :&lt;/p&gt;

&lt;pre&gt;
all:
  .settings:
    escaping_strategy: both
    escaping_method:   ESC_ENTITIES
&lt;/pre&gt;


&lt;p&gt;Ainsi, dans notre cas toutes les chaînes seront échappées en entités HTML pour plus de sécurité. Pour plus d'information, rendez-vous dans la &lt;a href=&quot;http://www.symfony-project.com/book/trunk/07-Inside-the-View-Layer#Output%20Escaping&quot; hreflang=&quot;fr&quot;&gt;section dédiée de la documentation officielle&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Au final, voici ce que ça donne quand on édite un billet :&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://prendreuncafe.com/blog/public/images/Geekeries/Symfony/sf_admin_posts_comments.png&quot;&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Geekeries/Symfony/.sf_admin_posts_comments_m.jpg&quot; alt=&quot;Affichage des commentaires d'un billet&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;Champs virtuels&lt;/h3&gt;


&lt;p&gt;Notre liste de billets, pour l'instant, ne nous informe pas pour chacun le nombre de commentaires associés. On va y remédier simplement en créant un getter ad-hoc dans notre objet de donnée &lt;code&gt;Post&lt;/code&gt; et en appellant le champs virtuel associé. Dans le fichier &lt;code&gt;lib/model/Post.php&lt;/code&gt;, on rajoute la méthode suivante :&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; getCommentsNumber&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: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;countComments&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;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Et dans le fichier &lt;code&gt;apps/back/modules/posts/config/generator.yml&lt;/code&gt;, on affiche le champs virtuel &lt;code&gt;comments_number&lt;/code&gt; dans la vue en liste :&lt;/p&gt;

&lt;pre&gt;
  [...]

    # Customisation des colones de la vue en liste
    list:
      display:         [=title, excerpt, Author, comments_number, created_at, updated_at]
&lt;/pre&gt;


&lt;p&gt;Voici ce que ça donne :&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://prendreuncafe.com/blog/public/images/Geekeries/Symfony/sf_admin_posts_4.png&quot;&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Geekeries/Symfony/.sf_admin_posts_4_m.jpg&quot; alt=&quot;Liste des billets, avec nombre de commentaires associés&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;En conclusion&lt;/h3&gt;


&lt;p&gt;Voila, notre application prend forme doucement. On pourrait passez des heures à ajouter des détails par-ci par-là, mais je vous laisse le faire en compagnie de la &lt;a href=&quot;http://www.symfony-project.com/book&quot; hreflang=&quot;en&quot;&gt;documentation&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;</description>
    
    
    
      </item>
    
  <item>
    <title>Gagnez du temps avec Symfony 1.0 et son générateur de back-office</title>
    <link>http://prendreuncafe.com/blog/post/2007/04/28/Gagnez-du-temps-avec-Symfony-et-son-generateur-de-back-office</link>
    <guid isPermaLink="false">urn:md5:976cd47651753a1d2e008e0e9e8380fa</guid>
    <pubDate>Sat, 28 Apr 2007 16:26:00 +0200</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>bestpractices</category><category>framework</category><category>php</category><category>scaffolding</category><category>symfony</category><category>tutoriel</category>    
    <description>    &lt;p&gt;Lors du dernier &lt;a href=&quot;http://www.clever-age.com/actualites/petits-dejeuners/paris/&quot; hreflang=&quot;fr&quot;&gt;petit-déjeuner&lt;/a&gt; Clever Age que j'ai animé sur les frameworks PHP, j'ai effectué une démonstration des fonctionnalités de génération de back-office existantes dans &lt;a href=&quot;http://www.symfony-project.com&quot; hreflang=&quot;fr&quot;&gt;Symfony&lt;/a&gt; : la plupart des gens présents - pour la plupart découvrant la notion même de &lt;em&gt;framework&lt;/em&gt; - ont été très impressionnés par la facilité déconcertante avec laquelle il était possible de développer une application complète en très peu de temps et d'étapes techniques grâce au &lt;a href=&quot;http://www.symfony-project.com/book/trunk/14-Generators#Administration&quot; hreflang=&quot;en&quot;&gt;générateur d'admin&lt;/a&gt;...&lt;/p&gt;


&lt;p&gt;Personnellement, je suis tellement habitué à travailler avec de tels outils désormais que j'oublie parfois comme la vie est plus difficile sans eux... Je vais donc faire une démonstration afin que chacun puisse se faire son idée, sur sa propre machine &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;Pour faire très original, on va créer une petite application sommaire de gestion de weblog, doté des fonctionnalités suivantes :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Un auteur par billet&lt;/li&gt;
&lt;li&gt;Billets multi-catégoriques (on pourrait aussi parler de tags)&lt;/li&gt;
&lt;li&gt;Commentaires pour chaque billet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;L'avantage est que la plupart des frameworks web proposent ce type de tutoriaux, donc ainsi vous pourrez plus aisément comparer &lt;img src=&quot;/blog/themes/PuC4/smilies/smile.gif&quot; alt=&quot;:)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;Installation de Symfony&lt;/h3&gt;


&lt;p&gt;Je vous renvoie à la &lt;a href=&quot;http://www.symfony-project.com/book/trunk/03-Running-Symfony&quot; hreflang=&quot;fr&quot;&gt;documentation officielle&lt;/a&gt; ou à &lt;a href=&quot;http://prendreuncafe.com/blog/post/2006/06/20/473-installer-le-framework-php-symfony-sur-ubuntu-dapper-drake&quot; hreflang=&quot;fr&quot;&gt;ce tutoriel&lt;/a&gt; pour installer Symfony sur votre machine et configurer un &lt;a href=&quot;http://httpd.apache.org/docs/2.2/fr/vhosts/examples.html&quot; hreflang=&quot;fr&quot;&gt;vhost apache&lt;/a&gt; pour votre nouveau projet. On partira sur la &lt;strong&gt;version 1.0.2&lt;/strong&gt;, soit la dernière version stable disponible à l'heure où sont écrites ces quelques lignes.&lt;/p&gt;


&lt;h3&gt;Création d'un nouveau projet&lt;/h3&gt;


&lt;p&gt;Imaginons que votre projet soit créé dans /var/www :&lt;/p&gt;


&lt;pre&gt;$ sudo -s
# cd /var/www
# mkdir sftest &amp;amp;&amp;amp; cd sftest
# symfony init-project sftest&lt;/pre&gt;


&lt;p&gt;Note: Si la page web par défaut du projet n'affiche pas d'images, il se peut que votre vhost ne trouve pas les éléments médias génériques de Symfony ; dans ce cas, un lien symbolique comme ci-dessous devrait régler le problème :&lt;/p&gt;


&lt;pre&gt;# ln -s /usr/share/php/data/symfony/web/sf web/sf&lt;/pre&gt;


&lt;p&gt;Note : Vous pourriez tout autant utiliser un alias apache dans votre vhost.&lt;/p&gt;


&lt;p&gt;Créons maintenant nos deux applications &lt;code&gt;front&lt;/code&gt; et &lt;code&gt;back&lt;/code&gt; qui recevront le front-office et la console d'administration de notre projet :&lt;/p&gt;


&lt;pre&gt;# symfony init-app front 
# symfony init-app back&lt;/pre&gt;


&lt;p&gt;On crée une base de données dédiée au projet :&lt;/p&gt;


&lt;pre&gt;# mysql -uroot -p
&amp;gt; CREATE DATABASE sftest CHARACTER SET utf8 COLLATE utf8_general_ci;
&amp;gt; GRANT ALL ON sftest.* TO sftest@localhost IDENTIFIED BY '1234567'
&amp;gt; FLUSH PRIVILEGES;
&amp;gt; \q&lt;/pre&gt;


&lt;h3&gt;Configuration de l'accès à la base de données&lt;/h3&gt;


&lt;p&gt;D'abord, on renseigne notre &lt;acronym title=&quot;Data Source Name&quot;&gt;DSN&lt;/acronym&gt; MySQL dans le fichier &lt;code&gt;config/databases.yml&lt;/code&gt; :&lt;/p&gt;


&lt;pre&gt;all:
  propel:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://sftest:1234567@localhost/sftest&lt;/pre&gt;


&lt;p&gt;On fait la même chose pour Propel, dans le fichier &lt;code&gt;config/propel.ini&lt;/code&gt; :&lt;/p&gt;


&lt;pre&gt;propel.database.url = mysql://sftest:1234567@localhost/sftest&lt;/pre&gt;


&lt;h3&gt;Configuration du modèle de données&lt;/h3&gt;


&lt;p&gt;On crée le schéma de base notre de données, dans le fichier &lt;code&gt;config/schema.yml&lt;/code&gt; :&lt;/p&gt;

&lt;pre&gt;
propel:

  blog_authors:
    _attributes:    { phpName: Author }
    id: 
    name:           varchar(255)
    email:          varchar(255)

  blog_posts:
    _attributes:    { phpName: Post }
    id: 
    title:          varchar(255)
    excerpt:        longvarchar
    body:           longvarchar
    author_id:
    created_at:
    updated_at:
  
  blog_comments:
    _attributes:    { phpName: Comment }
    id: 
    post_id:
    author:         varchar(255)
    email:          varchar(255)
    site:           varchar(255)
    content:        longvarchar
    created_at:

  blog_sections:
    _attributes:    { phpName: Section }
    id: 
    name:           varchar(255)

  blog_posts_sections:
    _attributes:    { phpName: PostSection }
    id: 
    post_id:
    section_id:
&lt;/pre&gt;


&lt;p&gt;Il y a beaucoup de magie dans la syntaxe de ce fichier. Retenez juste que les champs &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;*_id&lt;/code&gt; et &lt;code&gt;*_at&lt;/code&gt; sont nommés en vertus de conventions Symfony pour gérer automatiquement clés primaires, clés étrangères et les champs de type DATETIME.&lt;/p&gt;


&lt;h3&gt;Création d'un jeu de données de test&lt;/h3&gt;


&lt;p&gt;De même et parce qu'on est des gens sérieux (mais surtout parceque c'est pratique), on crée d'emblée un jeu de données de test (ou &lt;em&gt;fixtures&lt;/em&gt;), dans un nouveau fichier &lt;code&gt;data/fixtures/data.yml&lt;/code&gt; :&lt;/p&gt;

&lt;pre&gt;
Author:
  NiKo:
    name:    NiKo
    email:   tepafou@fai.com

Post:
  FirstPost:
    title:   Mon premier post !
    excerpt: Un premier billet prometteur...
    body: &amp;gt;
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer 
      consectetuer congue diam. Sed eu enim. Cras fringilla, erat et pretium 
      tincidunt, elit nibh imperdiet lectus, vel viverra erat velit in  
      metus. Ut ipsum ante, ornare luctus, hendrerit in, ultricies id, est.
    author_id: NiKo
  
  SecondPost:
    title:   Mon deuxième billet
    excerpt: Un deuxième billet tout aussi savoureux.
    body: &amp;gt;
      Suspendisse potenti. Mauris id risus. Cras urna. Etiam vel enim nec 
      dui ultrices condimentum. Curabitur bibendum ultrices quam. Nulla 
      sodales risus eget nunc.
    author_id: NiKo

Section:
  Humeurs:
    name:    Humeurs
  Geek: 
    name:    Geek
  Ubuntu:
    name:    Ubuntu

PostSection:
  # First post categories
  FirstPost_Humeurs:
    post_id: FirstPost
    section_id: Humeurs
  FirstPost_Geek: 
    post_id: FirstPost
    section_id: Geek

  # Second post categories
  SecondPost_Geek:
    post_id: SecondPost
    section_id: Geek
  SecondPost_Geek: 
    post_id: SecondPost
    section_id: Ubuntu

Comment:
  Comment1:
    post_id: FirstPost
    author:  Jean-Paul
    email:   &amp;quot;jp@fai.com&amp;quot;
    site:    &amp;quot;http://blog.jeanpaul.com&amp;quot;
    content: Bravo, belle intervention.

  Comment2:
    post_id: SecondPost
    author:  Jean-Luc
    email:   &amp;quot;jl@fai.com&amp;quot;
    site:    &amp;quot;http://blog.jeanluc.org&amp;quot;
    content: Exactement, vous avez raison.
&lt;/pre&gt;


&lt;p&gt;Ceci fait, on va lancer la génération du fichier SQL et des classes représentant notre modèle, créer les tables physiquement dans notre base et insérer notre jeu de données de test :&lt;/p&gt;


&lt;pre&gt;# symfony propel-build-all-load back&lt;/pre&gt;


&lt;p&gt;Vous noterez qu'un seule ligne de commande est à appeller, ce qui simplifie grandement les phases de prototypage.&lt;/p&gt;


&lt;p&gt;Note : En cas de modification profonde du modèle de données, il est vivement conseillé de vider le cache symfony :&lt;/p&gt;


&lt;pre&gt;# symfony cc&lt;/pre&gt;


&lt;h3&gt;Ajout des méthodes &lt;code&gt;__toString()&lt;/code&gt; aux objets de données&lt;/h3&gt;


&lt;p&gt;Afin d'avoir facilement un descripteur texte pour notre objet &lt;code&gt;Author&lt;/code&gt;, nous allons implémenter une méthode &lt;code&gt;__toString()&lt;/code&gt; dans sa classe associée située dans le fichier &lt;code&gt;lib/model/Author.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;class&lt;/span&gt; Author extends BaseAuthor
&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; __toString&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: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getName&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;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Cette méthode retournera le contenu du champs &lt;code&gt;name&lt;/code&gt; de l'enregistrement de la table &lt;code&gt;blog_authors&lt;/code&gt; correspondant pour identifier l'objet PHP sous la forme d'une chaîne de caractère descriptive. Vous pouvez aussi adapter ce principe pour les objets &lt;code&gt;Post&lt;/code&gt; et &lt;code&gt;Section&lt;/code&gt;, par exemple.&lt;/p&gt;


&lt;h3&gt;Génération d'un back-office d'administration des billets&lt;/h3&gt;


&lt;p&gt;Maintenant, on va générer une interface d'administration de nos objets &lt;code&gt;Post&lt;/code&gt;, accessible par un contrôleur &lt;code&gt;/posts&lt;/code&gt; depuis notre application &lt;code&gt;back&lt;/code&gt; :&lt;/p&gt;


&lt;pre&gt;# symfony propel-init-admin back posts Post&lt;/pre&gt;


&lt;p&gt;L'interface d'administration est maintenant accessible via &lt;code&gt;/back_dev.php/posts&lt;/code&gt; derrière la racine de l'url de votre instance projet Symfony &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/public/images/Geekeries/Symfony/sf_admin_posts1.png&quot;&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Geekeries/Symfony/.sf_admin_posts1_s.jpg&quot; alt=&quot;Administration des billets&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;C'est un peu sec par défaut et les sections associées aux billets du blog ne sont pas gérées, il nous faut donc adapter le fichier de configuration du générateur d'admin de Symfony pour ce module, situé dans le fichier &lt;code&gt;apps/back/modules/posts/config/generator.yml&lt;/code&gt; :&lt;/p&gt;

&lt;pre&gt;
generator:
  class:               sfPropelAdminGenerator
  param:
    model_class:       Post
    theme:             default

    # Customisation des colones de la vue en liste, lien d'édition sur le titre
    list:
      display:         [=title, excerpt, Author, created_at, updated_at]

    # Customisation du formulaire d'ajout/édition
    edit:
    
      # Champs personnalisés
      fields:
        # Création d'un champs d'administration des sections associées
        post_sections: { type: admin_check_list, params: through_class=PostSection }
    
      # Spécification des champs de formulaire à afficher
      display:         [author_id, title, excerpt, body, post_sections]
&lt;/pre&gt;


&lt;p&gt;Un raffraîchissement des interfaces en mode développement (en appellant le contrôleur &lt;code&gt;back_dev.php&lt;/code&gt; dans l'url) affichera nos interfaces modifiées en conséquences. Si vous utilisez le contrôleur de production (&lt;code&gt;/back.php&lt;/code&gt;), n'oubliez pas de vider le cache symfony pour visualiser vos modifications :&lt;/p&gt;


&lt;pre&gt;# symfony cc&lt;/pre&gt;


&lt;p&gt;On reproduira exactement la même opération pour nos autres objets à administrer (&lt;code&gt;Author&lt