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

<channel>
	<title>Blog d'un développeur multi-support &#187; framework</title>
	<atom:link href="http://www.oni-ecchi.info/blog/tag/framework/feed" rel="self" type="application/rss+xml" />
	<link>http://www.oni-ecchi.info/blog</link>
	<description>[DIM] pour les intimes :)</description>
	<lastBuildDate>Fri, 18 Jun 2010 06:27:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Symfony 1.2, behavior doctrine en actions</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/symfony-1-2-behavior-doctrine-en-actions.html#comments</comments>
		<pubDate>Sat, 03 Oct 2009 21:49:46 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutoriel]]></category>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=148</guid>
		<description><![CDATA[Bonjour,
Cette semaine j&#8217;ai du rendre pour l&#8217;école des gobelins le jeux que j&#8217;ai fait avec un . Comme ce projet est fini, et que je ne pense pas que je vais en faire grand chose de mon coté, je vais vous en expliquer le fonctionnement. Peut être que ça vous sera utile.
I) Installation
L&#8217;installation de slick [...]]]></description>
			<content:encoded><![CDATA[<p>Bonjour,</p>
<p>Cette semaine j&#8217;ai du rendre pour l&#8217;école des gobelins le jeux que j&#8217;ai fait avec un <a class="shal" href=" http://www.oni-ecchi.info/blog/decouverte-java/framework-java-pour-le-jeux.html" title=" Framework Java pour le jeux">framework java</a>. Comme ce projet est fini, et que je ne pense pas que je vais en faire grand chose de mon coté, je vais vous en expliquer le fonctionnement. Peut être que ça vous sera utile.</p>
<h3>I) Installation</h3>
<p>L&#8217;installation de slick dans un projet eclipse  est assez déroutante pour un newbie JAVA (j&#8217;y ai passé une demi journée de cours ^^) même avec<a rel="nofollow" href="http://www.cs.bsu.edu/homepages/pvg/misc/slick_eclipse_tutorial.php" target="_blank"> un très bon (l&#8217;unique ?) tutoriel d&#8217;installation. </a>Faites bien attention au dernier point, c&#8217;est important.</p>
<p>En fait Slick est basé sur un autre framework nommée <a rel="nofollow" href="http://lwjgl.org/" target="_blank">lwgl</a>, il y a donc deux librairies pour le prix d&#8217;une. Vive la réutilisation ! Slick étant un framework dédié aux un jeux 2D, il fait le ménage dans lwgl des choses non indispensables et rajoute tout ce qui va bien pour la 2D.</p>
<p>Passons au code !</p>
<h3>II) Premier Exemple</h3>
<p>Je pars du principe que votre installation est fonctionnelle. Voici le code de mon premier test slick. Il s&#8217;agissait d&#8217;afficher une image, un test, et grâce au clavier de faire pivoter cette image. Le principe de base est le même pour le jeux final.</p>
<p>J&#8217;ai commenter tout le code pour vous expliquer pas à pas ce qu&#8217;il se passe.</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('p148code25'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14825"><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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
</pre></td><td class="code" id="p148code25"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.BasicGame</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.GameContainer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.Graphics</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.Image</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.Input</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.SlickException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.AppGameContainer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.newdawn.slick.util.Log</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Il faut étendre la classe BasicGame</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SimpleTest <span style="color: #000000; font-weight: bold;">extends</span> BasicGame <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// L'image tourne, il faut un petit angle non ?</span>
	<span style="color: #666666; font-style: italic;">// En fait il en faut un pour se souvenir d'un FPS à l'autre de combien il</span>
	<span style="color: #666666; font-style: italic;">// faut tourner l'image.</span>
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a> angle_image <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a> imgToTurn<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Il faut un constructeur de base.</span>
	<span style="color: #666666; font-style: italic;">// Vous noterez que toutes les erreurs seront catchés au moment de</span>
	<span style="color: #666666; font-style: italic;">// l'exécution. (c'est à dire, dans le main)</span>
	<span style="color: #000000; font-weight: bold;">public</span> SimpleTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Initialise le nom de la fenetre ..</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SimpleTest&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Très pratique pour débuger l'application. Remplace le</span>
		<span style="color: #666666; font-style: italic;">// System.out.println .. et plus si affinié</span>
		Log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;je viens d'être initialisé&quot;</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;">// Initialise mes objets. Exécuté au lancement du jeux.</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>GameContainer container<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// J'ai besoin d'une image.</span>
		imgToTurn <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Image</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ressources/images/woman.jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Méthode appelé en boucle. C'est ici que l'on fait vivre nos objets</span>
	<span style="color: #666666; font-style: italic;">// &quot;non graphique&quot; comme la gestion des touches, de nos propriétés (comme</span>
	<span style="color: #666666; font-style: italic;">// angle) etc</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> update<span style="color: #009900;">&#40;</span>GameContainer container, <span style="color: #000066; font-weight: bold;">int</span> delta<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Si on appuie sur la fleche Haut</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>container.<span style="color: #006633;">getInput</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isKeyDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Input.<span style="color: #006633;">KEY_UP</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			angle_image<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// Si on appuie sur la fleche Bas</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>container.<span style="color: #006633;">getInput</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isKeyDown</span><span style="color: #009900;">&#40;</span>Input.<span style="color: #006633;">KEY_DOWN</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			angle_image<span style="color: #339933;">--;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// On fait en sorte que notre angle &quot;tourne en rond&quot; ^^</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>angle_image <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">360</span><span style="color: #009900;">&#41;</span>
			angle_image <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Méthode appelé en boucle. C'est ici qu'on gére l'affichage.</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> render<span style="color: #009900;">&#40;</span>GameContainer container, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphics+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Graphics</span></a> g<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> SlickException <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Affiche un hello world en x:0 et y:100</span>
		g.<span style="color: #006633;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello, Slick world!&quot;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #006633;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;coucou&quot;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Je fais tourner l'image</span>
		imgToTurn.<span style="color: #006633;">setRotation</span><span style="color: #009900;">&#40;</span>angle_image<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Et je la rajoute à ma fenetre</span>
		g.<span style="color: #006633;">drawImage</span><span style="color: #009900;">&#40;</span>imgToTurn, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Démarre un jeux à partir de ma classe</span>
			AppGameContainer app <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AppGameContainer<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SimpleTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			app.<span style="color: #006633;">setTargetFrameRate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			app.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SlickException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Et c'est ici que je catch les erreurs de toutes mes méthodes.</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Wahou non ? on a fait un jeux à partir de 5 fonctions, dans l&#8217;ordre :</p>
<ol>
<li>constructeur() &#8211; Spécifie la fenetre de jeux (icone, intitulé de fenetre ..)</li>
<li>init()  &#8211; Initialise tout nos objets</li>
<li> update() &#8211; Gestion du clavier et mis à jours d&#8217;objet non graphique</li>
<li> render() &#8211; Gestion de l&#8217;affichage, c&#8217;est là qu&#8217;on affiche ou non des éléments graphiques (image, texte, animation, etc)</li>
<li>main() &#8211; Il faut bien un point d&#8217;entré non ? On peut aussi s&#8217;en servir comme point de récupération des erreurs.</li>
</ol>
<p>Bon ca casse pas trois pattes à un canard, mais en moins de 100 lignes de codes avec les commentaires on s&#8217;en sort plutôt pas mal non ?</p>
<table border="0" align="center">
<tbody>
<tr>
<td><a href="http://www.oni-ecchi.info/blog/wp-content/uploads/2009/01/2009-01-25_1349.png"><img class="aligncenter size-thumbnail wp-image-173" title="SimpleTest" src="http://www.oni-ecchi.info/blog/wp-content/uploads/2009/01/2009-01-25_1349-150x150.png" alt="SimpleTest" width="150" height="150" /></a></td>
<td><a href="http://www.oni-ecchi.info/blog/wp-content/uploads/2009/01/2009-01-25_1350.png"><img class="aligncenter size-thumbnail wp-image-174" title="SimpleTest-2" src="http://www.oni-ecchi.info/blog/wp-content/uploads/2009/01/2009-01-25_1350-150x150.png" alt="SimpleTest-2" width="150" height="150" /></a></td>
</tr>
</tbody>
</table>
<p><span id="more-148"></span></p>
<h3>III) Pour aller plus loin</h3>
<p>Vous avez vu comment créer une fenetre, l&#8217;animer, et utiliser les écouteurs de touches. A ce stade là, vous pouvez commencer à créer vos <a class="shal" href=" http://www.oni-ecchi.info/blog/decouverte-java/framework-java-pour-le-jeux.html" title=" Framework Java pour le jeux">jeux</a>. Mais ne partez pas sans connaitre une fonctionnalité vraiment sympa dans Slick, le support de <a rel="nofollow" href="http://www.mapeditor.org/screenshots.html" target="_blank">Tiled</a>.</p>
<p style="text-align: center;">Tiled est un générateur de carte en java comme vous pouvez le voir <a href="http://www.oni-ecchi.info/blog/wp-content/uploads/2008/12/collision_layer_example.png"><img class="size-medium wp-image-117 aligncenter" title="Editeur de carte Tiled" src="http://www.oni-ecchi.info/blog/wp-content/uploads/2008/12/collision_layer_example-300x200.png" alt="Editeur de carte Tiled" width="300" height="200" /></a></p>
<p style="text-align: left;">En fait, en créant une carte avec Tiled, vous avez la possibilité de définir des propriétés pour chaque case (appelé tile) et vous pouvez les lire en Java très simplement. Voici un extrait de ma fonction init() (souvenez vous, c&#8217;est là qu&#8217;on initialise tout le jeux). Action !</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('p148code26'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14826"><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
</pre></td><td class="code" id="p148code26"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Charge la map</span>
map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TiledMap<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ressources/level/lvl1.tmx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Initialise mes différents vecteurs</span>
caseGagnante <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avector+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Vector</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
blocked <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Avector+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Vector</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;">// build a collision map based on tile properties in the TileD map</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>lt<span style="color: #339933;">;</span> map.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>lt<span style="color: #339933;">;</span> map.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> tileID <span style="color: #339933;">=</span> map.<span style="color: #006633;">getTileId</span><span style="color: #009900;">&#40;</span>x, y, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Hydratation du vecteur de Collision</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> value <span style="color: #339933;">=</span> map.<span style="color: #006633;">getTileProperty</span><span style="color: #009900;">&#40;</span>tileID, <span style="color: #0000ff;">&quot;blocked&quot;</span>, <span style="color: #0000ff;">&quot;false&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;true&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			blocked.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apoint+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Point</span></a><span style="color: #009900;">&#40;</span>x, y<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;">// Hydratation du vecteur de case Gagnante</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> value2 <span style="color: #339933;">=</span> map.<span style="color: #006633;">getTileProperty</span><span style="color: #009900;">&#40;</span>tileID, <span style="color: #0000ff;">&quot;winCase&quot;</span>, <span style="color: #0000ff;">&quot;false&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;true&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>value2 <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				caseGagnante.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apoint+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Point</span></a><span style="color: #009900;">&#40;</span>x, y<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>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Et voilà, vous avez deux beaux vecteur rempli de bonne choses que vous pourrez exploiter par la suite. Par exemple, pour savoir si la position où l&#8217;on veut allé est &laquo;&nbsp;blocked&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('p148code27'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14827"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p148code27"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> blocked<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> x, <span style="color: #000066; font-weight: bold;">float</span> y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Log.info((int)x+&quot;-&quot;+(int)y +&quot; bloquer ?&quot;);</span>
    <span style="color: #000000; font-weight: bold;">return</span> blocked.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apoint+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Point</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> x, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ou bien, autre façon pour savoir si on est sur une case gagnante c&#8217;est de parcourir le vecteur à la main :</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('p148code28'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14828"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p148code28"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Test si on est sur une case Gagnante</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>lt<span style="color: #339933;">;</span> caseGagnante.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apoint+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Point</span></a> point <span style="color: #339933;">=</span> caseGagnante.<span style="color: #006633;">elementAt</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> point.<span style="color: #006633;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> playerX <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> point.<span style="color: #006633;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> playerY<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			lvlComplete <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// que l'on aurait pu simplifier par</span>
lvlComplete  <span style="color: #339933;">=</span> caseGagnante.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apoint+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Point</span></a><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span>playerX, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#41;</span> playerY<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>IV) Autres éléments</h3>
<p>Vous avez vu que les images sont gérer de façon vraiment simple dans Slick (cf SimpleTest), et bien les sons c&#8217;est la même chose. Voyez par vous même :</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('p148code29'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14829"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p148code29"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// On joue un son wav</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	Sound fireSound  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Sound<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ressources/sound/rocket-Part1.wav&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fireSound.<span style="color: #006633;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SlickException e1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
		e1.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</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 il y a la classe Animation, qui permet à partir de plusieurs images de créer dynamiquement une animation type gif. Si votre personnage est définit sur plusieurs images, vous pouvez le faire courir très simplement :</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('p148code30'); return false;">View Code</a> JAVA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14830"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p148code30"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Charge la libraire graphique</span>
SpriteSheet sheet <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SpriteSheet<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ressources/images/sprites.png&quot;</span>,
<span style="color: #cc66cc;">32</span>, <span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// create the player sprite based on a set of sprites from the sheet</span>
<span style="color: #666666; font-style: italic;">// loaded above (tank tracks moving)</span>
Animation player <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Animation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> frame <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> frame <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span> frame<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	player.<span style="color: #006633;">addFrame</span><span style="color: #009900;">&#40;</span>sheet.<span style="color: #006633;">getSprite</span><span style="color: #009900;">&#40;</span>frame, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 150 est la duré de l'animation en milliseconde</span>
<span style="color: #009900;">&#125;</span>
player.<span style="color: #006633;">setAutoUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Puis quand vous voulez jouer l'animation, dans la méthode update par exemple</span>
player.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>delta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// delta représente un entier, la clé de la frame à afficher.</span></pre></td></tr></table></div>

<p>Voici d&#8217;autres éléments que je n&#8217;ai pas testé mais qui ont l&#8217;air bien :</p>
<ul>
<li>Il y a une classe Music qui a l&#8217;air sympa vu que l&#8217;on peut ajouter des écouteurs d&#8217;évènement sur la musique en cours..</li>
<li>Le pathFinding est aussi géré. Ça a l&#8217;air assez simple.</li>
<li>Un générateur de particule est intégré  O_o  J&#8217;aurais pu faire mes explosions avec ^^</li>
</ul>
<h3>V) Conclusion</h3>
<p>Voici mon projet éclipse au complet, libre à vous de vous en inspirer/copier/critiquer.</p>
<blockquote><p><a href="/blog/wp-content/uploads/2009/01/MyGames.zip">Mon jeux Slick</a></p>
</blockquote>
<p>Sinon mon jeux est bidon au passage. C&#8217;est un pauvre Tank qui doit se déplacer d&#8217;un point A à un point B sans se faire exploser par des tourelles, et y a 5 map (la flemme d&#8217;en générer plus avec Tiled). Voilà voilà.</p>
<p>Pour en revenir à Slick :</p>
<ul>
<li>c&#8217;est sympa</li>
<li>c&#8217;est simple</li>
<li>Y a une bonne documentation dans l&#8217;ensemble (en francais aussi  O_o)</li>
<li>faut essayer.</li>
</ul>
<p>Bonne journée</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-java/slick-en-detail.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Framework Java pour le jeux</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-java/framework-java-pour-le-jeux.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-java/framework-java-pour-le-jeux.html#comments</comments>
		<pubDate>Wed, 24 Dec 2008 09:59:11 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte Java]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jeux]]></category>
		<category><![CDATA[jeux video]]></category>
		<category><![CDATA[slick]]></category>
		<category><![CDATA[vidéo]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=113</guid>
		<description><![CDATA[Introduction
Dans le cadre de ma formation &#171;&#160;développeur informatique multi-support&#160;&#187; on nous a demandé de créer un jeux en Java en 2D de type &#171;&#160;mario&#160;&#187; ou plutôt de modifier un jeux existant en vue d&#8217;apprendre par nous même le java et d&#8217;en voir un coté plus sexy que les habituelles programmes en ligne de commande.
Voici l&#8217;url [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Dans le cadre de ma formation &laquo;&nbsp;développeur informatique multi-support&nbsp;&raquo; on nous a demandé de créer un jeux en Java en 2D de type &laquo;&nbsp;mario&nbsp;&raquo; ou plutôt de modifier un jeux existant en vue d&#8217;apprendre par nous même le java et d&#8217;en voir un coté plus sexy que les habituelles programmes en ligne de commande.</p>
<p>Voici l&#8217;url que l&#8217;on nous a donné : <a href="http://fivedots.coe.psu.ac.th/~ad/jg/ch062/index.html" target="_blank">http://fivedots.coe.psu.ac.th/~ad/jg/ch062/index.html</a>. Ce chapitre est un extrait du livre <em><span style="color: #cc3300;">Killer Game Programming in Java</span></em> présenté par son auteur sur le site <a href="http://fivedots.coe.psu.ac.th/~ad/jg">http://fivedots.coe.psu.ac.th/~ad/jg</a>. Sur ce dernier vous trouverez d&#8217;autres jeux et d&#8217;autres chapitres intéressant.</p>
<p>Seulement je n&#8217;ai pas pour habitude d&#8217;apprendre en traficotant des exemples de code. Je le faisais quand je débutais en programmation, mais maintenant je pense être capable d&#8217;apprendre par moi même et de partir sur une base propre. Comme un framework par exemple !!</p>
<h3>Les Frameworks Java</h3>
<p>L&#8217;idée d&#8217;utiliser un framework java et capitaliser le temps des cours en une expérience riche m&#8217;est venu en regardant l&#8217;écran de <a href="http://www.epivoila.com/" target="_blank">Clément Biron</a> et <a href="http://www.palleas.com">Romain pouclet</a> qui s&#8217;intéressaient tout deux aux frameworks &laquo;&nbsp;<a href="http://processing.org/" target="_blank">processing&nbsp;&raquo; </a>et à  <a href="http://www.interactivepulp.com/pulpcore/" target="_blank">&laquo;&nbsp;PulpCore&nbsp;&raquo;</a>. (Il faut toujours cité ses sources :))</p>
<p>Alors pour maximiser nos découvertes je suis parti dans la découverte d&#8217;un troisième framework nommé <a href="http://slick.cokeandcode.com/" target="_blank">Slick.</a> Voila un bref apercu de ces frameworks après une journé à les regarder.</p>
<h4>Processing</h4>
<p>En un mot : Enorme. Le couteau suisse par exellence, ce framework s&#8217;adresse à tout le monde :</p>
<p><cite class="aligncenter">&nbsp;&raquo; for people who want to program images, animation, and interactions. It is used by          students, artists, designers, researchers, and hobbyists for          learning, prototyping, and production.&nbsp;&raquo;</cite></p>
<p>Personnellement, j&#8217;ai été bluffé par Processing quand j&#8217;ai vu cette vidéo :</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="302" 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=1663988&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="302" src="http://vimeo.com/moogaloop.swf?clip_id=1663988&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></p>
<p><a href="http://vimeo.com/1663988"></a><a href="http://bricktable.wordpress.com/about/what-is-roots/">http://bricktable.wordpress.com/about/what-is-roots/</a> Du java rapide O_o wahou !</p>
<p>Bien sur cela ne se limite pas qu&#8217;à ça :) Il y a quand même 6 livres qui sont sorties sur ce framework ! &laquo;&nbsp;Ça envoie du lourd&nbsp;&raquo; comme dirait certains :)</p>
<h4>Pulpcore</h4>
<p>Pulpcore je le vois plutôt comme un moyen d&#8217;embarquer du java dans des pages web de façon transparente et se rapproche plus de Flash. <a href="http://www.pulpgames.net/milpa/">Exemple ici </a>et <a href="http://www.pulpgames.net/scared/">un autre exemple là</a>.</p>
<p>Bien que jeune, ce framework  tant à se faire connaitre avec son slogan provocateurs &laquo;&nbsp;Applets are back&nbsp;&raquo; :)</p>
<h4>Slick</h4>
<p>A la base, on nous a demandé de faire un jeux. Processing étant quand même énorme, et pulcore un peu trop limitatif, il fallait que je trouve un framework &laquo;&nbsp;médiant&nbsp;&raquo;. Hors <a href="http://slick.cokeandcode.com/" target="_blank">Slick</a> se positionne exclusivement comme étant LE framework dédié aux jeux 2D en java.  Great !</p>
<p>En gros, il fournit tout ce qu&#8217;on a besoin pour un jeux : gestion du clavier, gestion des collisions, gestion des cartes via <a href="http://www.mapeditor.org/screenshots.html" target="_blank">Tiled</a></p>
<div id="attachment_117" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.oni-ecchi.info/blog/wp-content/uploads/2008/12/collision_layer_example.png"><img class="size-medium wp-image-117" title="collision_layer_example" src="http://www.oni-ecchi.info/blog/wp-content/uploads/2008/12/collision_layer_example-300x200.png" alt="" width="300" height="200" /></a><p class="wp-caption-text">Tiled, Le Map editor supporté par Slick</p></div>
<p>Je reviendrais en détail sur ce framework en expliquant comment créer un jeux, ou du moins je mettrais le code source à disposition. Mais vous pouvez voir un exemple de code source ici : <a href="http://www.oni-ecchi.info/blog/wp-content/uploads/2008/12/scroller.java">Un tank se déplacement sur une carte avec gestions des collisions !</a></p>
<h3>Et vous ?</h3>
<p>Si on vous demandez de faire un jeux Java en 2D, vous partiriez sur quoi ?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-java/framework-java-pour-le-jeux.html/feed</wfw:commentRss>
		<slash:comments>2</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 Symfony, 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;;
$stmt-&#62;;bindParam&#40;2, $param2, PDO::PARAM_STR, 255&#41;;
$stmt-&#62;bindParam&#40;3, $param3, PDO::PARAM_STR, 255&#41;;
$res = $stmt-&#62;execute&#40;&#41;;

Magie, c&#8217;est la même chose. On remercie PDO et son abstracteur [...]]]></description>
			<content:encoded><![CDATA[<p>Dans un article précédent, je créais la procédure stocké &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('p94code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9432"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p94code32"><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>[Mysql] Procédure Stocké</title>
		<link>http://www.oni-ecchi.info/blog/sql/mysql-procedure-stocke.html</link>
		<comments>http://www.oni-ecchi.info/blog/sql/mysql-procedure-stocke.html#comments</comments>
		<pubDate>Tue, 02 Dec 2008 19:29:45 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[procédure stocké]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=91</guid>
		<description><![CDATA[Pour un projet d&#8217;annuaire de Flux RSS, j&#8217;ai du faire en sorte que l&#8217;on puisse importer ses Flux dans l&#8217;annuaire via un fichier XML opml que tout bon agrégateur (google reader, netvibes) fournit. Donc admettons que l&#8217;on a 100 flux RSS à importer il faut pour chaque flux vérifier si le flux n&#8217;existe pas déjà [...]]]></description>
			<content:encoded><![CDATA[<p>Pour un projet d&#8217;annuaire de Flux RSS, j&#8217;ai du faire en sorte que l&#8217;on puisse importer ses Flux dans l&#8217;annuaire via un fichier XML opml que tout bon agrégateur (google reader, netvibes) fournit. Donc admettons que l&#8217;on a 100 flux RSS à importer il faut pour chaque flux vérifier si le flux n&#8217;existe pas déjà sinon le créer en base. Donc il faut prévoir un maximum de 200 requêtes SQL.</p>
<p>Seulement voilà, si on fait les instructions de test d&#8217;existence et d&#8217;insertion au niveau PHP, cela fait 200 aller retour entre PHP et la base Mysql. Hors ce qui plombe un script c&#8217;est souvent ces aller retour incessants .. Un moyen d&#8217;optimiser ce traitement a été de créer une procédure stocké qui prend en paramètre le fichier XML (où plutôt une représentation épuré plus strict), et de faire exécuter les 200 requêtes DANS Mysql. Chouette non ? Plus rapide, plus stable, plus optimisé .. que du bonheur.</p>
<h3>Procédure Stocké en Mysql</h3>
<p>Vous allez rire, mais d&#8217;après mes recherches googlidiennes très peu de personnes font des procédures en Mysql. Cela vient sans doute du fait qu&#8217;elles sont apparru avec mysql 5 et que c&#8217;est encore &laquo;&nbsp;neuf&nbsp;&raquo;.</p>
<p>Tous les exemples que l&#8217;on trouve sur le sujet sont pour SQL serveur PRo, donc du transact-SQL. Et le souci c&#8217;est qu&#8217;il n&#8217;y pas forcement d&#8217;équivalence entre les fonctions transact-SQL et les fonctions mysql. La synthaxe n&#8217;est décidement pas la même.</p>
<h3>Outil utilisé</h3>
<p><a href="http://dev.mysql.com/downloads/gui-tools/5.0.html">Mysql query browser !</a></p>
<p>L&#8217;exemple que je donne n&#8217;est valable qu&#8217;a travers sont interface .. zarb.. m&#8217;enfin c&#8217;est un très bon outil quand même, rien à voir avec un phpMyAdmin tout POURRI !</p>
<h3>Création de la requête</h3>
<p>Voilà la précédure allégé que j&#8217;ai crée (je fais d&#8217;autres test en version un peu plus lourde). Je vais essayer de la commenter au mieux.</p>
<p>La procédure s&#8217;appelle import, elle est dans la base de donné nommé &laquo;&nbsp;Fluxe&nbsp;&raquo; et on l&#8217;appelle et l&#8217;utilise comme ceci</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('p91code35'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9135"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p91code35"><pre class="sql" style="font-family:monospace;">call import<span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">&quot;premier flux|http://monsite|http://monsite/fluxrss|description;
deuxieme flix|http://monsite2|http://www.google.fr/bidule.xml|autre description;
troisieme|http://monsite3|http://monsite2/rss.xml|description;&quot;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Le premier paramètre est la chaine retravaillé coté PHP qui correspond à chaque ligne de l&#8217;XML, et le deuxième paramètre est le nombre de flux. Une entré se fini via un &laquo;&nbsp;;&nbsp;&raquo; et chaque colonne est séparé via un &nbsp;&raquo; | &laquo;&nbsp;. Bon je sais, mes délimiteurs ne sont pas assez complexe dans cet exemple et cela serait risque de bug si une description ou url comporterait des points virgules et des pipes&#8230;</p>
<p>Voici la requête :</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('p91code36'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9136"><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
</pre></td><td class="code" id="p91code36"><pre class="sql" style="font-family:monospace;">DELIMITER $$  <span style="color: #808080; font-style: italic;">-- pas trop compris l'interet O_o</span>
<span style="color: #993333; font-weight: bold;">DROP</span> PROCEDURE <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`fluxe`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`import`</span> $$
<span style="color: #808080; font-style: italic;">-- Supprime la procédure si elle existe (je suis fort en anglais hein ? ^^) </span>
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> DEFINER<span style="color: #66cc66;">=</span><span style="color: #ff0000;">`root`</span>@<span style="color: #ff0000;">`localhost`</span> PROCEDURE <span style="color: #ff0000;">`import`</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">In</span> myCsv Text<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">In</span> nbElement Int<span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">-- crée la procédure avec deux paramètres &quot;IN&quot; de type Text et Int. C'est à dire que c'est deux paramètres obligatoires pour exécuter la requête.  </span>
&nbsp;
BEGIN <span style="color: #808080; font-style: italic;">-- Debut de la procédure</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Declare mes variables correspondant aux colonnes de ma table Flux</span>
DECLARE nom varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
DECLARE urlSite varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
DECLARE myurlFlux varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
DECLARE description text;
DECLARE  ligne_flux VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">-- correspondra à une ligne de Flux</span>
DECLARE cpt int; <span style="color: #808080; font-style: italic;">-- un petit compteur pour faire une jolie boucle While</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">set</span> cpt <span style="color: #66cc66;">=</span> nbElement;  <span style="color: #808080; font-style: italic;">-- / !  Voilà comment on définit une variable SET var = valeur; </span>
&nbsp;
WHILE cpt <span style="color: #66cc66;">&lt;=</span> nbElement <span style="color: #993333; font-weight: bold;">and</span> cpt <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> do  <span style="color: #808080; font-style: italic;">-- j'aurais pu utiliser une boucle Loop aussi.</span>
&nbsp;
  <span style="color: #993333; font-weight: bold;">select</span> <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>myCsv<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">';'</span><span style="color: #66cc66;">,</span> cpt<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>myCsv<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">';'</span><span style="color: #66cc66;">,</span> cpt <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">';'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">as</span> ligne <span style="color: #993333; font-weight: bold;">into</span> ligne_flux;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Outch &quot;KEKECER ?&quot; vous devez vous pausez comme question :)</span>
  <span style="color: #808080; font-style: italic;">-- c'est simple, je découpe le premier paramètre In pour en extraire la 1er ligne trouvé.</span>
  <span style="color: #808080; font-style: italic;">-- Les fonctions appellés ne sont pas du php mais bien du SQL ! Puissant non ?</span>
  <span style="color: #808080; font-style: italic;">-- l'idée de récupèrer la 1er ligne DANS une variable &quot;ligne_flux&quot;, d'où le &quot;select ... INTO variable&quot; </span>
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Parsage de la chaine &quot;ligne_flux&quot; pour en extraire les colonnes, rebelote quoi ..</span>
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> nom;
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> urlSite;
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> myurlFlux;
  <span style="color: #993333; font-weight: bold;">select</span>  <span style="color: #993333; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>substring<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> length<span style="color: #66cc66;">&#40;</span>substring_index<span style="color: #66cc66;">&#40;</span>ligne_flux<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">into</span> description;
&nbsp;
  <span style="color: #808080; font-style: italic;">-- Insertion que si la ligne n'existe pas. Le critère est l'url du flux.</span>
  <span style="color: #993333; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">from</span> flux <span style="color: #993333; font-weight: bold;">where</span> urlFlux <span style="color: #66cc66;">=</span> myurlFlux<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> THEN
       <span style="color: #993333; font-weight: bold;">insert</span> <span style="color: #993333; font-weight: bold;">into</span> flux <span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">,</span>urlSite<span style="color: #66cc66;">,</span>urlFlux<span style="color: #66cc66;">,</span>description<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">values</span> <span style="color: #66cc66;">&#40;</span>nom<span style="color: #66cc66;">,</span>urlSite<span style="color: #66cc66;">,</span>myurlFlux<span style="color: #66cc66;">,</span>description<span style="color: #66cc66;">&#41;</span>;
   end <span style="color: #993333; font-weight: bold;">if</span>;
&nbsp;
 <span style="color: #808080; font-style: italic;">-- on décrémente le compteur</span>
 <span style="color: #993333; font-weight: bold;">set</span> cpt <span style="color: #66cc66;">=</span> cpt <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span>;
end while;
&nbsp;
END $$
DELIMITER ;</pre></td></tr></table></div>

<p>Et voilà c&#8217;est fini !</p>
<h3>Lien de référence</h3>
<p>La base :<a href="http://dev.mysql.com/doc/refman/5.0/fr/stored-procedure-syntax.html">http://dev.mysql.com/doc/refman/5.0/fr/stored-procedure-syntax.html</a></p>
<p>les variables : <a href="http://dev.mysql.com/doc/refman/5.0/fr/variables-in-stored-procedures.html">http://dev.mysql.com/doc/refman/5.0/fr/variables-in-stored-procedures.html</a><br />
If, while, case, et tous les contrôles : <a href="http://dev.mysql.com/doc/refman/5.0/fr/flow-control-constructs.html">http://dev.mysql.com/doc/refman/5.0/fr/flow-control-constructs.html</a></p>
<p>Mis à part la documentation officiel, j&#8217;ai rien trouvé d&#8217;autres à me mettre sous la dent ..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/sql/mysql-procedure-stocke.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Validé un formulaire en Ajax avec Symfony 1.1</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html#comments</comments>
		<pubDate>Sat, 06 Sep 2008 16:59:29 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

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

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code45'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3545"><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="p35code45"><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('p35code46'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3546"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code46"><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('p35code47'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3547"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code47"><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('p35code48'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3548"><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="p35code48"><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('p35code49'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3549"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p35code49"><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('p35code50'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3550"><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="p35code50"><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('p35code51'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3551"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p35code51"><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('p35code52'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3552"><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="p35code52"><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>
