<?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&#039;un développeur multi-support &#187; Découverte PHP</title>
	<atom:link href="http://www.oni-ecchi.info/blog/category/decouverte-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.oni-ecchi.info/blog</link>
	<description>[DIM] pour les intimes :)</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:51:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>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) [...]]]></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 <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">symfony</a> pour du reverse engineirng). Le souci du reverse c&#8217;est que ça produisait trop de <a href="http://www.oni-ecchi.info/blog/tag/code" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec code">code</a> 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 [...]]]></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é à <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">symfony</a>.</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>5</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 [...]]]></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.<a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">php</a>&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 <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">Symfony</a>.. 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 <a href="http://www.oni-ecchi.info/blog/tag/framework" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec framework">framework</a> 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>10</slash:comments>
		</item>
		<item>
		<title>Spip c&#8217;est le mal</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/spip-cest-le-mal.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/spip-cest-le-mal.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 06:48:57 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[About me :)]]></category>
		<category><![CDATA[Découverte PHP]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/uncategorized/spip-cest-le-mal.html</guid>
		<description><![CDATA[Répétez après moi : Spip c&#8217;est le mal. Spip c&#8217;est le mal. Spip c&#8217;est le mal. Spip c&#8217;est le mal. Spip c&#8217;est le mal. Pourquoi ? parce que.]]></description>
			<content:encoded><![CDATA[<p>Répétez après moi : Spip c&#8217;est le mal.<br />
Spip c&#8217;est le mal.<br />
Spip c&#8217;est le mal.<br />
Spip c&#8217;est le mal.<br />
Spip c&#8217;est le mal.</p>
<p>Pourquoi ? parce que.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/spip-cest-le-mal.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>phpFlickr &amp; Flex</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-flex-flash/phpflickr-flex.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-flex-flash/phpflickr-flex.html#comments</comments>
		<pubDate>Fri, 30 Jan 2009 06:00:35 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[Flex Flash Floush]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=200</guid>
		<description><![CDATA[Pour un cours de , il nous avait été demandé de créer une application très simple constitué de deux écrans pour nous apprendre à manipuler les &#171;&#160;states&#160;&#187;, les composants personnalisés, le &#171;&#160;data binding&#160;&#187; etc. Le sujet de l&#8217;application était d&#8217;afficher des images en fonction d&#8217;une ville &#8211; en vue de faire du data binding sur [...]]]></description>
			<content:encoded><![CDATA[<p>Pour un cours de <a class="shal" href=" http://www.oni-ecchi.info/blog/decouverte-flex-flash/flex-et-numberformatter.html" title=" Découverte Flex : new NumberFormatter();">Flex</a>, il nous avait été demandé de créer une application très simple constitué de deux écrans pour nous apprendre à manipuler les &laquo;&nbsp;states&nbsp;&raquo;, les composants personnalisés, le &laquo;&nbsp;data binding&nbsp;&raquo; etc.</p>
<p>Le sujet de l&#8217;application était d&#8217;afficher des images en fonction d&#8217;une ville &#8211; en vue de faire du data binding sur un XML &laquo;&nbsp;statique&nbsp;&raquo; de villes &#8211; et de récupérer des images issues d&#8217;un XML dynamique via l&#8217;objet HTTPService.</p>
<p>Alors quitte à faire du dynamique, autant interroger directement un web service existant en vue de récupérer pleins d&#8217;images sans se prendre la tête. Et là j&#8217;ai pensé à FlickR et sa monstrueuse API. Après 5mn montre en main j&#8217;ai eu ma clé pour accèder à l&#8217;API et 4mn après je découvrait <a rel="nofollow" href="http://phpflickr.com/" target="_blank">phpFlickR</a>.</p>
<p>Upload de la librairie et voici mon bout de script qui me renvoit suivant deux paramètres en $_GET un joli XML près à être utilisé en <a href="http://www.oni-ecchi.info/blog/tag/flex" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec flex">Flex</a>.</p>
<ul>
<li> $_GET['town'] est le terme rechercher dans l&#8217;api FlickR sur les tags et le text qui commente une photo.</li>
<li>$_GET['max'] est le nombre de photos qu&#8217;il faudra retourner.</li>
</ul>

<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('p200code17'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20017"><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
</pre></td><td class="code" id="p200code17"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;phpFlickr.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$flickR</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> phpFlickr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ta_cle_de_connection_flickR&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 10 résultat par défaut ..</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'max'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'max'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span> <span style="color: #000088;">$max</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$search</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;tags&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'town'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'per_page'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$max</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tag_mode&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">&quot;any&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'text'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'town'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tab</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$flickR</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">photos_search</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// On renvoit un XML à Flex</span>
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-type: application/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// La balise qui va bien</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;?xml version=&quot;</span><span style="color:#800080;">1.0</span><span style="color: #0000ff;">&quot; encoding=&quot;</span>utf<span style="color: #339933;">-</span><span style="color: #cc66cc;">8</span><span style="color: #0000ff;">&quot; ?&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$max</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// on s'assure d'avoir des photos valides</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tab</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</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: #666666; font-style: italic;">// Simple de créer des urls FlickR non ?</span>
	<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$flickR</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildPhotoURL</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tab</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;thumbnail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$flickR</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildPhotoURL</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tab</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;medium&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;image&gt;&lt;url&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/url&gt;&lt;urlLarge&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$link</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/urlLarge&gt;&lt;/image&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La partie Flex est tout aussi simple, voici la partie essentielle qui nous intéresse :</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('p200code18'); return false;">View Code</a> ACTIONSCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20018"><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
43
44
45
46
</pre></td><td class="code" id="p200code18"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;searchPhoto('france',20)&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">http</span>.<span style="color: #006600;">HTTPService</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
&nbsp;
<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> servicePhoto:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> searchPhoto<span style="color: #66cc66;">&#40;</span>search:<span style="color: #0066CC;">String</span>,<span style="color: #0066CC;">max</span>:<span style="color: #0066CC;">int</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> modService:HTTPService = <span style="color: #000000; font-weight: bold;">new</span> HTTPService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	modService.<span style="color: #006600;">method</span> = <span style="color: #ff0000;">&quot;get&quot;</span>;
	modService.<span style="color: #0066CC;">url</span> = <span style="color: #ff0000;">&quot;http://oni-ecchi.info/labo/FlexPhotos/service.php&quot;</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> parameters:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	parameters.<span style="color: #006600;">town</span> = search;
	parameters.<span style="color: #0066CC;">max</span> = <span style="color: #0066CC;">max</span>;
	modService.<span style="color: #006600;">request</span> = parameters;                
	modService.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	modService.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,onDataCharged<span style="color: #66cc66;">&#41;</span>;                
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDataCharged<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	servicePhoto = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	servicePhoto = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">result</span>.<span style="color: #006600;">root</span>.<span style="color: #006600;">image</span> as ArrayCollection;		
	vignettes.<span style="color: #006600;">dataProvider</span> = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">result</span>.<span style="color: #006600;">root</span>.<span style="color: #006600;">image</span> as ArrayCollection;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:TileList id=<span style="color: #ff0000;">&quot;vignettes&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{servicePhoto}&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;481&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;279&quot;</span> columnWidth=<span style="color: #ff0000;">&quot;110&quot;</span> rowHeight=<span style="color: #ff0000;">&quot;110&quot;</span> columnCount=<span style="color: #ff0000;">&quot;4&quot;</span> horizontalCenter=<span style="color: #ff0000;">&quot;0&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> verticalCenter=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:itemRenderer<span style="color: #66cc66;">&gt;</span>
   		<span style="color: #66cc66;">&lt;</span>mx:Component<span style="color: #66cc66;">&gt;</span>
   			<span style="color: #66cc66;">&lt;</span>mx:Image  source=<span style="color: #ff0000;">&quot;{data.url}&quot;</span> verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span> horizontalAlign=<span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #66cc66;">/&gt;</span>
   		<span style="color: #66cc66;">&lt;/</span>mx:Component<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:itemRenderer<span style="color: #66cc66;">&gt;</span>       
<span style="color: #66cc66;">&lt;/</span>mx:TileList<span style="color: #66cc66;">&gt;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Ce n&#8217;est qu&#8217;un exemple très simple. Dans le fichier source qui va suivre, j&#8217;ai un peu plus travaillé la chose en utilisant un composant de chargement d&#8217;image sympathique, un spinner de chargement 2.0 et enfin la gestion des states (très simple).</p>
<ul>
<li><a href="/blog/wp-content/uploads/2009/01/FlexFlickR.zip" target="_blank">Mon Projet Flex (zip)<br />
</a></li>
<li><a href="http://oni-ecchi.info/labo/FlexPhotos/FlexFlickR.html" target="_blank">Le site d&#8217;exemple</a></li>
</ul>
<p>Voilà, c&#8217;est tout pour aujourd&#8217;hui</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-flex-flash/phpflickr-flex.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Et un framework un !</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/et-un-framework-un.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/et-un-framework-un.html#comments</comments>
		<pubDate>Fri, 12 Dec 2008 13:31:34 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[cakePHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[generateur]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[vidéo]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=107</guid>
		<description><![CDATA[Aller sur http://blog.jaysalvat.com/articles/model-baker-une-interface-graphique-a-la-creation-dapplications-cakephp.php ou regarder simplement son screencast : Model Baker in action from Jay Salvat on Vimeo. Ca a l&#8217;air génial :) Dommage que ça soit seulement pour mac pour l&#8217;instant, mais c&#8217;est très prometteurs ! Apres un tour sur Symfony, sur Zend, faudrait que j&#8217;aille voir CakePHP donc :)]]></description>
			<content:encoded><![CDATA[<p>Aller sur <a href="http://blog.jaysalvat.com/articles/model-baker-une-interface-graphique-a-la-creation-dapplications-cakephp.php">http://blog.jaysalvat.com/articles/model-baker-une-interface-graphique-a-la-creation-dapplications-cakephp.php</a> ou regarder simplement son screencast :<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="267" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=2337610&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="267" src="http://vimeo.com/moogaloop.swf?clip_id=2337610&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
<a href="http://vimeo.com/2337610">Model Baker in action</a> from <a href="http://vimeo.com/user740872">Jay Salvat</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Ca a l&#8217;air génial :) Dommage que ça soit seulement pour mac pour l&#8217;instant, mais c&#8217;est très prometteurs ! Apres un tour sur <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">Symfony</a>, sur Zend, faudrait que j&#8217;aille voir CakePHP donc :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/et-un-framework-un.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utiliser une procédure stocké mysql avec Zend !</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/utiliser-une-procedure-stocke-en-mysql.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/utiliser-une-procedure-stocke-en-mysql.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 19:40:29 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[procédure stocké]]></category>
		<category><![CDATA[transact-sql]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=94</guid>
		<description><![CDATA[Dans un article précédent, je créais la procédure stocké &#171;&#160;import&#160;&#187;, voilà comment je l&#8217;utilise dans Zend. Je n&#8217;invente rien, j&#8217;ai trouvé la manip sur http://www.ericmery.fr/blog/zend_db-sql-server-procedure-stockee. ?View Code PHP1 2 3 4 5 6 7 8 9 10 $registry = Zend_Registry::getInstance&#40;&#41;; $config = $registry-&#62;get&#40;&#34;config&#34;&#41;; &#160; $db = Zend_Db::factory&#40;$config-&#62;db&#41;; &#160; $stmt = $db-&#62;prepare&#40;&#34;call import(?,?,?);&#34;&#41;; $stmt-&#62;bindParam&#40;1, $param1, PDO::PARAM_STR,1000&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Dans un article précédent, je créais la <a href="http://www.oni-ecchi.info/blog/tag/procedure-stocke" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec procédure stocké">procédure stocké</a> &laquo;&nbsp;import&nbsp;&raquo;, voilà comment je l&#8217;utilise dans Zend.</p>
<p>Je n&#8217;invente rien, j&#8217;ai trouvé la manip sur <a href="http://www.ericmery.fr/blog/zend_db-sql-server-procedure-stockee/">http://www.ericmery.fr/blog/zend_db-sql-server-procedure-stockee.<br />
</a></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('p94code20'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9420"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p94code20"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<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;">;</span>
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;call import(?,?,?);&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param1</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;;</span>bindParam<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param2</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param3</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_STR</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Magie, c&#8217;est la même chose. On remercie PDO et son abstracteur de base de donnée utilisé !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/utiliser-une-procedure-stocke-en-mysql.html/feed</wfw:commentRss>
		<slash:comments>3</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 [...]]]></description>
			<content:encoded><![CDATA[<p>Depuis quelques jours, (2 semaines pour être exactes), je m&#8217;essai à <a href="http://www.oni-ecchi.info/blog/tag/zend-framework" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Zend framework">Zend Framework</a>. Et je le trouve pas mal.</p>
<p>Loin de moi l&#8217;idée de faire un <a href="http://www.oni-ecchi.info/blog/tag/comparatif" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec comparatif">comparatif</a>, mais voilà mon opinion entre Zend et <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">Symfony</a> &#8230;<span style="font-size: x-small;">mon coeur balance ^^</span></p>
<table>
<thead>
<tr>
<th></th>
<th>Symfony</th>
<th>Zend <a href="http://www.oni-ecchi.info/blog/tag/framework" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec framework">Framework</a></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>Hébergement de BOT</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/hebergement-de-bot.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/hebergement-de-bot.html#comments</comments>
		<pubDate>Sat, 27 Sep 2008 19:49:42 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutoriel]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=72</guid>
		<description><![CDATA[Dans un article précédent, nous avions vu comment créer un bot IRC en PHP. Seulement assurer la connexion du bot sur le salon était assez laborieux. Un processus php par bot qui tourne sur votre machine, c&#8217;est pas folichon. Mais grâce à http://new.imified.com, ce souci n&#8217;en est plus un ! Ce service web permet de [...]]]></description>
			<content:encoded><![CDATA[<p>Dans un article précédent, nous avions vu comment créer un bot <a href="http://www.oni-ecchi.info/blog/tag/irc" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec irc">IRC</a> en <a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">PHP</a>. Seulement assurer la connexion du bot sur le salon était assez laborieux. Un processus <a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">php</a> par bot qui tourne sur votre machine, c&#8217;est pas folichon.</p>
<p>Mais grâce à <a href="http://new.imified.com/">http://new.imified.com,</a> ce souci n&#8217;en est plus un ! Ce service web permet de connecter un bot à MSN, IRC, Gtalk etc et ce bot demandera à votre page PHP ce qu&#8217;il doit faire.</p>
<p>Au final nous n&#8217;avons plus qu&#8217;a se consacrer sur les réponses et les traitements à faire en fonction du dialogue de l&#8217;utilisateur (donnée récupérer sous forme de $_GET). Fini le parsage du stream pour détecter la bonne ligne ^^</p>
<p>Je vous avouerais, j&#8217;ai pas encore tester. Mais je compte le faire un de ces quatres :) Je pense que c&#8217;est LA solution pour créer rapidement un compagnon virtuel &#8230; Imaginer un bot de ce style qui pilote votre twitter, facebook etc. Vous lui parlez, il s&#8217;occupe du reste :)</p>
<p><cite class="aligncenter">Vu sur le channel #<a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">symfony</a>-fr (irc.freenode.com) grâce à [MA]Pascal.<br />
Il a crée un bot qui relaie ce que vous lui dites sur un site donné. (Système de prise de notes rapide) <br /> Ajouter <span style="font-size: small;"><span style="color: #000000;"><a href="mailto:paste@bot.im">paste@bot.im</a></span></span> à votre compte Gtalk et parler lui. Enfin, cela reste surtout un bot de test, réalisé avec Symfony 1.2 et Doctrine (un ORM comme propel) </cite></p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/hebergement-de-bot.html/feed</wfw:commentRss>
		<slash:comments>0</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 [...]]]></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 <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">Symfony</a> 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.<a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">php</a>

<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
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p35code29"><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('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
</pre></td><td class="code" id="p35code30"><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('p35code31'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3531"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code31"><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('p35code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3532"><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="p35code32"><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('p35code33'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3533"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p35code33"><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('p35code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3534"><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="p35code34"><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('p35code35'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3535"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p35code35"><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('p35code36'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3536"><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="p35code36"><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>

