<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog d'un développeur multi-support &#187; Symfony</title>
	<atom:link href="http://www.oni-ecchi.info/blog/tag/symfony/feed" rel="self" type="application/rss+xml" />
	<link>http://www.oni-ecchi.info/blog</link>
	<description>[DIM] pour les intimes :)</description>
	<lastBuildDate>Fri, 18 Jun 2010 06:27:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Symfony &amp; Doctrine &amp; schema.yml</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/symfony-doctrine-schema-yml.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/symfony-doctrine-schema-yml.html#comments</comments>
		<pubDate>Mon, 01 Feb 2010 19:00:35 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[découverte]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=504</guid>
		<description><![CDATA[J&#8217;espère que vous utilisé Doctrine car ce mini article pourrait vous plaire ! Quand vous débutez un projet, la partie conception BDD et création du fichier yml prennent du temps et on aimerait pouvoir faire tout d&#8217;un coup.
Personnellement je fais ma conception sur Workbench puis je repart &#171;&#160;from scratch&#160;&#187; pour faire mon (mes) fichier(s) yml. [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;espère que vous utilisé Doctrine car ce mini article pourrait vous plaire ! Quand vous débutez un projet, la partie conception BDD et création du fichier yml prennent du temps et on aimerait pouvoir faire tout d&#8217;un coup.</p>
<p>Personnellement je fais ma conception sur Workbench puis je repart &laquo;&nbsp;from scratch&nbsp;&raquo; pour faire mon (mes) fichier(s) yml. (Oui oui on peut en avoir plusieurs de yml :p). </p>
<p>Quand j&#8217;étais sur Propel J&#8217;avais perdu quelque cheveux quand j&#8217;avais essayé l&#8217;autre méthode (cad de générer le fichier SQL, l&#8217;insérer en base, et laisser faire symfony pour du reverse engineirng). Le souci du reverse c&#8217;est que ça produisait trop de code inutile (sur les foreign key par exemple) et au final repasser derrière pour arranger le model m&#8217;avait fait perdre pas mal de temps.</p>
<p>Hors ce soir j&#8217;ai trouvé, je ne sais comment, un plugin pour Workbench pour écrire  le fichier yml directement à partir de celui ci, adieu les étapes &laquo;&nbsp;insertion bdd, reverse&nbsp;&raquo;. Et en plus sur les (mini) tests que j&#8217;ai fait tout à l&#8217;air propre, les conventions doctrines sont respectés, tout est bien indiqué. Il suffit de suivre la marche à suivre suivante : <a href="http://code.google.com/p/mysql-workbench-doctrine-plugin/wiki/WorkbenchPreparationForDoctrinePlugin">http://code.google.com/p/mysql-workbench-doctrine-plugin/wiki/WorkbenchPreparationForDoctrinePlugin</a></p>
<p>Bref, en un mot c&#8217;est bon plugin Workbench bien utile :p</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/symfony-doctrine-schema-yml.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony 1.2, behavior doctrine en actions</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html#comments</comments>
		<pubDate>Sat, 03 Oct 2009 21:49:46 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=478</guid>
		<description><![CDATA[J&#8217;ai (re)découvert un truc vraiment sympathique au boulot c&#8217;est le système de behavior doctrine intégré à symfony.
Hein ? Mais à quoi ça sert ?
Ce que j&#8217;en retiens c&#8217;est que cela peut permettre d&#8217;automatiser certaines actions (répétitives) à l&#8217;enregistrement en base, et donc d&#8217;enrichir son modèle et deux coup de cuillère à pot.
Prenons un exemple, vous [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai (re)découvert un truc vraiment sympathique au boulot c&#8217;est le système de <strong>behavior doctrine</strong> intégré à symfony.</p>
<p><strong>Hein ? Mais à quoi ça sert ?</strong></p>
<p>Ce que j&#8217;en retiens c&#8217;est que cela peut permettre d&#8217;<strong>automatiser certaines actions</strong> (répétitives) à l&#8217;enregistrement en base, et donc d&#8217;enrichir son modèle et deux coup de cuillère à pot.</p>
<p><strong>Prenons un exemple,</strong> vous devez faire un site basé sur la créations de contenus par vos utilisateurs. Ils peuvent écrire des billets, commenter, s&#8217;envoyer des messages privés, gérer un annuaire .. bref un site où l&#8217;on doit quasiment tout relié à un utilisateur. Chaques tables auraient donc au moins un &laquo;&nbsp;user_id&nbsp;&raquo; comme clée étrangère ce qui implique dans vos actions d&#8217;associer l&#8217;utilisateur courant à l&#8217;objet pour le sauvegarder .. et ce pour chaque table &#8230; lourd non ?</p>
<p>Hé bien grâce aux behaviors vous pouvez sortir ce comportement générique dans des classes et avec seulement de la configuration au niveau de votre schéma, vous pouvez associer ce comportement à n&#8217;importe quel table. L&#8217;exemple que j&#8217;ai pris est tiré du behavior &laquo;&nbsp;<em>Signable</em>&nbsp;&raquo; du plugin <span><em>sfDoctrineActAsSignablePlugin</em>.</span></p>
<h3>Configuration</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code6'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4786"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p478code6"><pre class="yml" style="font-family:monospace;">Item:
  actAs:
    Signable:
  columns:
    id:
      type:             integer
      primary:          true
      autoincrement:    true
    champ1:             string(255</pre></td></tr></table></div>

<h3>Comment ça marche ?</h3>
<p>Donc si on résume, il faut dire à Doctrineque l&#8217;on va rajouter des colonnes .. et que l&#8217;on veut être prévénu lors de l&#8217;insertion en base pour associé nos actions. Donc avec seulement 2 classes, une de définition et une d&#8217;écoute, on peut s&#8217;en sortir et crée notre behavior.</p>
<p>Lors de la configuration, en rajoutant &laquo;&nbsp;actAs : Signable&nbsp;&raquo;, Doctrine va chercher une classe de définition qui ira  étendre une classe Doctrine_Template. Par convention il ira chercher une classe nommé Doctrine_Template_Signable. Le rôle de cette classe est de déclarer ses colonnes et de rajouter une écoute, un listener, vers l&#8217;autre classe d&#8217;actions.</p>
<p>Pour mon exemple, je vais volontairement raccourcir les classes du sfDoctrineActAsSignablePlugin et prendre pour acquis que vos utilisateurs sont gérés via sfGuardDoctrinePlugin.</p>
<h3>Doctrine_Template</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4787"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p478code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Doctrine_Template_Signable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Template <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Définitions des relations</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Bim rajoute une clée étrangère sur sfGuard</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasOne</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sfGuardUser as Author'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'local'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'created_by'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'foreign'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span>
            <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTableDefinition<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Bim une colonne en plus</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_by'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'integer'</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'4'</span><span style="color: #339933;">,</span>
     <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Lien avec notre 2eme classe .. on passe le nom de la colonnette rajouté</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Doctrine_Template_Listener_Signable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_by));
  }
}</span></pre></td></tr></table></div>

<p>Là pour l&#8217;exemple aucune configuration au niveau du schéma n&#8217;est possible mais c&#8217;est facile à rajouter via d&#8217;un tableau d&#8217;options et le constructeur suivant :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4788"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p478code8"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_options <span style="color: #339933;">=</span> Doctrine_Lib<span style="color: #339933;">::</span><span style="color: #004000;">arrayDeepMerge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_options<span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Doctrine_Template_Listener</h3>
<p>Nous avons vu que notre Template rajoute un listener vers notre 2e classe en lui passant la colonne à surveiller (dans la vrai vie, un tableau d&#8217;options ..). Le rôle de notre listener de pouvoir agir avant/après l&#8217;insertion/édition d&#8217;un objet .. facile :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4789"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code" id="p478code9"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Doctrine_Template_Listener_Signable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Record_Listener <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_colonette</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;created_by&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$colonne</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_colonette <span style="color: #339933;">=</span> <span style="color: #000088;">$colonne</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preInsert<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$createdName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_colonette<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// recupère l'objet appellant :</span>
      <span style="color: #000088;">$objet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInvoker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Affectation de valeur</span>
       <span style="color: #000088;">$objet</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$createdName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getUserId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// Echappe le mode cli</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">!=</span> <a href="http://www.php.net/strncasecmp"><span style="color: #990000;">strncasecmp</span></a><span style="color: #009900;">&#40;</span>PHP_SAPI<span style="color: #339933;">,</span> <span style="color: #0000ff;">'cli'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #666666; font-style: italic;">// L'user courant</span>
       <span style="color: #b1b100;">return</span> sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sfGuardSecurityUser'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> preUpdate<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postUpdate<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> postInsert<span style="color: #009900;">&#40;</span>Doctrine_Event <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// A tester : public function Delete(Doctrine_Event $event) ..</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p> Vous n&#8217;avez plus qu&#8217;a rebuilder votre model et magie ça doit marcher !! </p>
<p> Vu que l&#8217;on a fait une relation de type One-to-many sur sfGuard vous pouvez accéder à l&#8217;utilisateur sfGuard via la propriété Author sur n&#8217;importr quel table marqué comme &laquo;&nbsp;Signable&nbsp;&raquo; </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p478code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47810"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p478code10"><pre class="php" style="font-family:monospace;">  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$objet</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Author</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Voilà .. simple au final  non ? Ah vous de créez le votre, :p</p>
<p>Comme on dirait au boulot &laquo;&nbsp;Amaaziiiing !!&nbsp;&raquo;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Symfony 1.2 &amp; Personnalisation des pages 404 &amp; 500</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-personnalisation-des-pages-404-500.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-personnalisation-des-pages-404-500.html#comments</comments>
		<pubDate>Fri, 25 Sep 2009 14:14:55 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=471</guid>
		<description><![CDATA[Voici un petit tips sorti tout droit de jobeet pour personnaliser ses pages 404 &#38; 500 sur Symfony 1.2. C&#8217;est bête comme chou comme truc mais faut le savoir quoi.
Page 404 :
Pour la page 404 c&#8217;est dans le fichier settings de votre application
/apps/front/config/setting.yml
Il faut tout simplement rajouter ces deux directives

?View Code YML1
2
3
all:
  error_404_module: home
 [...]]]></description>
			<content:encoded><![CDATA[<p>Voici un petit tips sorti tout droit de jobeet pour personnaliser ses pages 404 &amp; 500 sur <a class="zem_slink" href="http://www.symfony-project.org/" title="Symfony" rel="homepage">Symfony</a> 1.2. C&#8217;est bête comme chou comme truc mais faut le savoir quoi.</p>
<h3>Page 404 :</h3>
<p>Pour la page 404 c&#8217;est dans le fichier settings de votre application<br />
/apps/front/config/setting.yml</p>
<p>Il faut tout simplement rajouter ces deux directives</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p471code13'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47113"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p471code13"><pre class="yml" style="font-family:monospace;">all:
  error_404_module: home
  error_404_action: error404</pre></td></tr></table></div>

<p>Du coup quand vous aurez une erreur 404 cela sera votre page qui sera affiché, vous pourrez donc dans votre action vous ajoutez une petite ligne pour vous envoyer un mail quand y a un souci. (Le plugin nahoMail est vraiment top d&#8217;ailleurs). Du monitoring pas cher quoi.</p>
<h3>Page 500 :</h3>
<p>Vous croyez qu&#8217;il aurait fallu mettre</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p471code14'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p47114"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p471code14"><pre class="yml" style="font-family:monospace;">all:   
   error_500_module: home 
   error_500_action: error500</pre></td></tr></table></div>

<p>Et bien ça ne marche pas du tout comme ça. Pour personnaliser cette page vous devez placer un fichier &laquo;&nbsp;error.html.php&nbsp;&raquo; dans le répertoire &laquo;&nbsp;apps/front/config/error&nbsp;&raquo; (crée le au besoin). Et c&#8217;est tout.</p>
<p>Mais du coup voilà, nous ne sommes pas dans une action .. donc cette page n&#8217;est pas inclu dans votre layout, on ne peut non plus utiliser les classes Symfony.. et oui <strong>la page d&#8217;erreur 500 est complétement statique. </strong>Adieu le monitoring pour cette page.</p>
<p>Si vous connaissez un moyen de customiser cette page et de pouvoir profiter du framework en même temps je suis preneur :p</p>
<p>Sur ceux, à bientôt pour de nouvelles astuces Symfony</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-personnalisation-des-pages-404-500.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Retour de vacances</title>
		<link>http://www.oni-ecchi.info/blog/guillaume-chave/retour-de-vacances.html</link>
		<comments>http://www.oni-ecchi.info/blog/guillaume-chave/retour-de-vacances.html#comments</comments>
		<pubDate>Fri, 28 Aug 2009 08:08:37 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[About me :)]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[moi]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=466</guid>
		<description><![CDATA[Me voici de retour,
Je préviens que ce blog risque de ne pas être mis à jour pendant encore un moment. J&#8217;emménage à Lyon, je change de job, et je n&#8217;aurais plus de mac pour développez sur iphone tout de suite. Donc pour les lecteurs &#171;&#160;iphone&#160;&#187; du blog désolé mais c&#8217;est chômage technique en vue.
C&#8217;est con, [...]]]></description>
			<content:encoded><![CDATA[<p>Me voici de retour,</p>
<p>Je préviens que ce blog risque de ne<strong> pas être mis à jour</strong> pendant encore un moment. J&#8217;emménage à <a class="zem_slink" title="Lyon" rel="geolocation" href="http://maps.google.com/maps?ll=45.7669444444,4.83416666667&amp;spn=0.1,0.1&amp;q=45.7669444444,4.83416666667%20%28Lyon%29&amp;t=h">Lyon</a>, je change de job, et je n&#8217;aurais plus de mac pour développez sur iphone tout de suite. Donc pour les lecteurs &laquo;&nbsp;iphone&nbsp;&raquo; du blog désolé mais c&#8217;est chômage technique en vue.</p>
<p>C&#8217;est con, j&#8217;aurais bien aimer tester la réalité augmenté sur iphone grâce à <a rel="nofollow" href="http://code.google.com/p/iphonearkit/" target="_blank">http://code.google.com/p/iphonearkit</a>. L&#8217;avez vous tester cette libraire vous ? Mais bon, je n&#8217;ai pas d&#8217;iphone 3GS non plus. D&#8217;ailleurs si vous avez un mac, un iphone 3GS que vous voulez me donner, y a pas de souci je prend :p</p>
<p><strong>Petite annonce iphone : </strong>Je suis à la recherche de dev iphone sur Lyon, débutant ou confirmé. N&#8217;hesitez pas à vous signaler par mail, je ne mord pas.</p>
<p>Par contre, pour ceux qui viennent pour du <strong><a class="zem_slink" title="PHP" rel="homepage" href="http://php.net/">PHP</a> et pour <a class="zem_slink" title="Symfony" rel="homepage" href="http://www.symfony-project.org/">Symfony</a> </strong>vont être content. Mon nouveau job m&#8217;en fera faire 8h par jour, je parie que je vais découvrir pleins de trucs que je posterais sur ce blog. :p</p>
<p><strong>Adieu objective-c, welcome PHP</strong>. (La tendance est de faire l&#8217;inverse, mais moi je ne suis pas comme les autres ;p)</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=b86059c6-fcb8-4624-aed9-8f314c839d9b" alt="" /><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/guillaume-chave/retour-de-vacances.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework !</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/zend-framework.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/zend-framework.html#comments</comments>
		<pubDate>Fri, 10 Oct 2008 16:00:10 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[comparatif]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=78</guid>
		<description><![CDATA[Depuis quelques jours, (2 semaines pour être exactes), je m&#8217;essai à Zend Framework. Et je le trouve pas mal.
Loin de moi l&#8217;idée de faire un comparatif, mais voilà mon opinion entre Zend et Symfony &#8230;mon coeur balance ^^




Symfony
Zend Framework




Documentation
Un bouquin papier pas à jour peut être fatal. Mais un bouquin dans les mains c&#8217;est bien [...]]]></description>
			<content:encoded><![CDATA[<p>Depuis quelques jours, (2 semaines pour être exactes), je m&#8217;essai à Zend Framework. Et je le trouve pas mal.</p>
<p>Loin de moi l&#8217;idée de faire un comparatif, mais voilà mon opinion entre Zend et Symfony &#8230;<span style="font-size: x-small;">mon coeur balance ^^</span></p>
<table>
<thead>
<tr>
<th></th>
<th>Symfony</th>
<th>Zend Framework</th>
</tr>
</thead>
<tbody>
<tr>
<td class="table_menu">Documentation</td>
<td>Un bouquin papier pas à jour peut être fatal. Mais un bouquin dans les mains c&#8217;est bien !</td>
<td><a href="http://php.developpez.com/livres/?page=en#L9781933988320" target="_blank">Un livre sort en novembre</a>, mais pour l&#8217;instant on reste à lire de long manuel sur écran.</td>
</tr>
<tr>
<td class="table_menu">Prise en main</td>
<td>Rapide avec un bouquin :)</td>
<td>Lente, le manuel Zend est fait pour ceux qui connaissent ou ont l&#8217;habitude de le parcourir. Ce n&#8217;est pas une écriture didactique comme Symfony je trouve.</td>
</tr>
<tr>
<td class="table_menu">Utilisation quotidienne</td>
<td>J&#8217;aime me concentrer seulement sur la logique applicative, j&#8217;aime tous les outils donnés en ligne de commande.</td>
<td>Le lego, une deuxième passion. Tout refaire, c&#8217;est flatteur pour l&#8217;égo et se dire &laquo;&nbsp;Ouais, j&#8217;ai tout compris&nbsp;&raquo;.</td>
</tr>
<tr>
<td class="table_menu">Rapidité d&#8217;exécution pour un projet simpe</td>
<td>Ouais ben ca rame un peu vu le nombre d&#8217;inclusion qu&#8217;il y a, mais c&#8217;est la rançon du succès.<br />
&laquo;&nbsp;Plus d&#8217;aide tu donneras, plus lent tu seras.&nbsp;&raquo;</td>
<td>I have the controll. Pardonner mon anglais déplorable, mais tout géré donne l&#8217;illusion de rapidité etc. C&#8217;est vrai et c&#8217;est faux. Ca dépend du développeur derrière :)</td>
</tr>
</tbody>
</table>
<p>Merde, c&#8217;est un comparatif très objectif. Tans pis. Vous noterez que je préfère symfony (c&#8217;est mon 1er framework alors bon c&#8217;est normal ^^).</p>
<p>Mais comme dirais un Romain &#8230; &laquo;&nbsp;le framework dépend du projet, desfois c&#8217;est mieux sans&nbsp;&raquo; :)</p>
<p>Sur ceux, bonne journée</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/zend-framework.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Validé un formulaire en Ajax avec Symfony 1.1</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html#comments</comments>
		<pubDate>Sat, 06 Sep 2008 16:59:29 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=35</guid>
		<description><![CDATA[Dans ce billet nous allons voir comment utiliser Ajax pour valider champ par champ un formulaire constuit avec sfForm de Symfony 1.1.
Je prend pour acquis que vous ayez lu / que vous connaissez la validatation de formulaire &#171;&#160;classique&#160;&#187; offert par sfForm. Tout est expliqué là et surtout là.
En fait le souci avec les validateurs symfony [...]]]></description>
			<content:encoded><![CDATA[<p>Dans ce billet nous allons voir comment utiliser Ajax pour valider champ par champ un formulaire constuit avec sfForm de Symfony 1.1.</p>
<p>Je prend pour acquis que vous ayez lu / que vous connaissez la validatation de formulaire &laquo;&nbsp;classique&nbsp;&raquo; offert par sfForm. Tout est expliqué <a href="http://www.symfony-project.org/book/forms/1_1/fr/" target="_blank">là </a>et surtout <a href="http://www.symfony-project.org/book/forms/1_1/fr/02-Form-Validation" target="_blank">là</a>.</p>
<p>En fait le souci avec les validateurs symfony 1.1 est qu&#8217;ils ne possèdent pas la méthode isValid() contraitement aux validateurs symfony 1.0. Du coup, quand on fait de l&#8217;ajax, nous sommes obligés de passer d&#8217;un type de validateur à un autre.</p>
<p>Cette exemple illuste le fait avec le validateur sfValidatorEmail (sf 1.1) et sfEmailValidator (sf 1.0). L&#8217;idée est de définir les paramêtres du validateur (les messages d&#8217;erreurs dans notre cas) qu&#8217;à un seul endroid afin de respecter le concept Dry (Don&#8217;t Repeat Yourself).</p>
<p>Voilà les étapes nécessaires pour mettre en place une validation de formulaire classique et &laquo;&nbsp;Ajaxé&nbsp;&raquo; :</p>
<ol>
<li>Vous créez vos widgets dans lib/form/MaClasseForm.class.php

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code23'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3523"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p35code23"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MaClasseForm <span style="color: #000000; font-weight: bold;">extends</span> BaseMaClassForm
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWidgets</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'id'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputHidden<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'FirstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'LastName'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'Email'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password_repeat'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// On peut modifier les labels si besoin est ...</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabels</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'FirstName'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Prenom'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'Email'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'addresse Email '</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'LastName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Nom'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Vous définissez vos validateurs dans lib/form/MaClasseForm.class.php à la suite de la méthode configure()

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3524"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code24"><pre class="php" style="font-family:monospace;">&nbsp;
 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValidators</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'id'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPropelChoice<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Utilisateurs'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'FirstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'LastName'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'password'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'password_repeat'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Email'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorEmail<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Birthday'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDate<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// J'en profite pour definir un nom formater des champs pour avoir $_POST['utilisateurs['email']] etc</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNameFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utilisateurs[%s]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li> Normallement à ce stade vous pouvez utiliser la classe de formulaire dans votre fichier apps/MonApp/MonModule/actions/actions.class.php

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3525"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code25"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeMonAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formInscription</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaClasseForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// récupère les champs du formulaire sous forme de tableau.</span>
     <span style="color: #000088;">$array_champ</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utilisateurs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formInscription</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array_champ</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formInscription</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
       <span style="color: #666666; font-style: italic;">// Formulaire valide.</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Voilà la validation &laquo;&nbsp;classique&nbsp;&raquo; et faite. Et l&#8217;ajax dans tout ça ? On y vient ^^ Alors au lieu d&#8217;afficher le formulaire de manière classique (via le template adéquate apps/MonApp/MonModule/templates/MonActionSuccess.php)

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3526"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p35code26"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Au lieu de</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// On va rendre le template comme on le souhaite</span>
<span style="color: #666666; font-style: italic;">// Par souci de flemme je ne fait que le champ Email</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>span id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error_for_email &quot;</span><span style="color: #339933;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>ul <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error_list&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&lt;</span>getError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #339933;">&lt;</span>li <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error_for&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$error</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
<li> Et maintenant on va jouer avec l&#8217;ajax pour vérifier ce champ email lors de la saisie.

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3527"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p35code27"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/************** Ajax Time :) *****************/</span>
<span style="color: #666666; font-style: italic;">// Dans le template on met :</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Crée l'observateur pour le champ utilisateurs_email du formulaire.</span>
<span style="color: #b1b100;">echo</span> observe_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utilisateurs_email&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'update'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;error_for_email&quot;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;MonModule/VerifierEmail&quot;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'with'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;'email='+ value&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</li>
<li>On rajoute l&#8217;action VerifierEmail() dans le fichier d&#8217;actions.

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3528"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code" id="p35code28"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeVerifierEmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	 <span style="color: #666666; font-style: italic;">// Initialisation des variables internes</span>
	 <span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$array_erreur</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">// Récupère le validateur d'email définit dans lib/form/MaClasseForm.class.php</span>
	 <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaClasseForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$validateur_form</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidatorSchema</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$all_validateurs_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validateur_form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$all_validateurs_field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">// Récupere le bon code d'erreur</span>
	 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$array_erreur</span> <span style="color: #339933;">=</span>	<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #b1b100;">else</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$array_erreur</span> <span style="color: #339933;">=</span>	<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;invalid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">// Crée un validateur d'email hérité de Symfony 1.0</span>
	 <span style="color: #000088;">$validateur_email</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfEmailValidator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// Un peu de Dry (Don't Repeat Yourself) afin d'éviter d'avoir des messages d'erreurs définit à deux endroits différents.</span>
	 <span style="color: #000088;">$validateur_email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array_erreur</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #666666; font-style: italic;">// Dispatcheur vers le bon templates</span>
	 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$validateur_email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span>true<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #b1b100;">else</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span>false<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
&nbsp;
	 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderText</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message_a_afficher</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Donc en fait on met à jour le &laquo;&nbsp;span&nbsp;&raquo; error_for_email avec le résultat de l&#8217;appel de la méthode VerifierEmail(). J&#8217;ai utilisé un template partial car le but est de le réutiliser pour tous les appels en Ajax. Celui ci n&#8217;est pas bien compliqué

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code29'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3529"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p35code29"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php if(<span style="color: #006699; font-weight: bold;">$reussi</span>) echo &quot;</span>accept_for<span style="color: #0000ff;">&quot;; else echo &quot;</span>error_for<span style="color: #0000ff;">&quot;; ?&gt;&quot;</span><span style="color: #339933;">&gt;&amp;</span>amp<span style="color: #339933;">;</span>nbsp<span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
<li>Et voilà, le formulaire fonctionne classiquement et dispose de vérifications en Ajax aussi.</li>
</ol>
<p>Nous venons de voir le validateur d&#8217;Email, mais tous fonctionnent sur le même principe. Voici la méthode pour utiliser le validateur de Sting qui diffère un peu.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3530"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code" id="p35code30"><pre class="php" style="font-family:monospace;">   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeVerifierPseudo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// Initialisation des variables internes</span>
    <span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pseudo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Récupère le validateur de pseudo</span>
    <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaClasseForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validateur_form</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidatorSchema</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$all_validateurs_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validateur_form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validateurs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$all_validateurs_field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;FirstName&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pseudo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validateurs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pseudo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Crée un validateur de String sf1.0</span>
    <span style="color: #000088;">$validateur_pseudo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfStringValidator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validateur_pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'min'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'min_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'max'</span> <span style="color: #339933;">=&gt;</span><span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'max_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Dispatcheur vers le bon templates</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$validateur_pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$bool</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">// Remplace les jokers des messages d'erreurs.</span>
     <span style="color: #000088;">$min</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_retour</span><span style="color: #339933;">=</span>    <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#%value%#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$chaine_a_verifier</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_retour</span><span style="color: #339933;">=</span>    <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#%min_length%#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$min</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_retour</span><span style="color: #339933;">=</span>    <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#%max_length%#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$max</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span>false<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderText</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message_a_afficher</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p> Et voilà c&#8217;est fini :) </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
