<?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 Symfony2 - Lexik Montpellier &#187; Samuel Breton</title>
	<atom:link href="http://www.lexik.fr/blog/symfony/author/admin/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lexik.fr/blog/symfony</link>
	<description>Blog sur le développement Web PHP avec Symfony 2</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:00:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Apéro Web Montpellier &#8211; Jeudi 8 Septembre 2011</title>
		<link>http://www.lexik.fr/blog/symfony/lexik-life/apero-web-montpellier-jeudi-8-septembre-2011-1683</link>
		<comments>http://www.lexik.fr/blog/symfony/lexik-life/apero-web-montpellier-jeudi-8-septembre-2011-1683#comments</comments>
		<pubDate>Thu, 01 Sep 2011 12:03:02 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Lexik Life]]></category>
		<category><![CDATA[apero]]></category>
		<category><![CDATA[montpellier]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1683</guid>
		<description><![CDATA[Toi l&#8217;ami qui travaille dans le Web, rejoins nous à l&#8217;apéro Web de Montpellier : Date : Jeudi 8 Septembre Lieu : au Fitzpatrick&#8217;s Irish pub (Map) Heure : à partir de 18H30. Vous pensez venir, passez sur le Doodle! &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/lexik-life/apero-web-montpellier-jeudi-8-septembre-2011-1683">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Toi l&#8217;ami qui travaille dans le Web, rejoins nous à l&#8217;apéro Web de Montpellier :</p>
<p>Date : Jeudi 8 Septembre<br />
Lieu : au Fitzpatrick&#8217;s Irish pub (<a href="http://maps.google.fr/maps/place?hl=fr&amp;prmd=ivns&amp;prmdo=1&amp;bav=on.2,or.r_gc.r_pw.&amp;biw=1280&amp;bih=963&amp;um=1&amp;ie=UTF-8&amp;q=fitzpatrick+montpellier&amp;fb=1&amp;gl=fr&amp;hq=fitzpatrick&amp;hnear=0x12b6af0725dd9db1:0xad8756742894e802,Montpellier&amp;cid=9273875162430621950">Map</a>)<br />
Heure : à partir de 18H30.</p>
<p>Vous pensez venir, passez <a href="http://www.doodle.com/3xannd5r9vgwkxqr">sur le Doodle</a>!</p>
<p>Les apéros web ont pour objectif de donner un cadre d&#8217;échange aux acteurs du web. Que vous soyez développeurs, webdesigner, chef de projet agile ou non, au marketing, ou resp. d&#8217;entreprise les apéros web vous permettront de discuter hors contexte entreprise / travail de votre métier et pouvoir échanger librement sur vos problématiques.</p>
<p><a href="http://www.lexik.fr/blog/symfony/wp-content/uploads/2011/09/aperoLexik.jpg"><img class="size-full wp-image-1747 alignnone" title="aperoLexik" src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2011/09/aperoLexik.jpg" alt="" width="600" height="337" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/lexik-life/apero-web-montpellier-jeudi-8-septembre-2011-1683/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony2 launch party à Montpellier</title>
		<link>http://www.lexik.fr/blog/symfony/lexik-life/symfony2-launch-party-a-montpellier-1655</link>
		<comments>http://www.lexik.fr/blog/symfony/lexik-life/symfony2-launch-party-a-montpellier-1655#comments</comments>
		<pubDate>Wed, 27 Jul 2011 16:58:21 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Lexik Life]]></category>
		<category><![CDATA[Symfony2]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1655</guid>
		<description><![CDATA[Fêtons de lancement de Symfony2 au Shakespeare A partir de 19H00 The Shakespeare Pub 12 Rue de la Petite Loge, 34000 Montpellier 04 67 60 22 25 ‎ Agrandir le plan]]></description>
			<content:encoded><![CDATA[<p><strong>Fêtons de lancement de Symfony2 au Shakespeare</strong></p>
<p>A partir de 19H00<br />
The Shakespeare Pub<br />
12 Rue de la Petite Loge, 34000 Montpellier<br />
04 67 60 22 25 ‎<br />
<span id="more-1655"></span><br />
<iframe src="http://maps.google.fr/maps?f=q&amp;source=s_q&amp;hl=fr&amp;geocode=&amp;q=Le+Shakespeare,+Rue+de+la+Petite+Loge,+Montpellier&amp;aq=1&amp;sll=46.75984,1.738281&amp;sspn=12.360483,19.753418&amp;ie=UTF8&amp;hq=Le+Shakespeare,&amp;hnear=Rue+de+la+Petite+Loge,+34000+Montpellier,+H%C3%A9rault,+Languedoc-Roussillon&amp;ll=43.610598,3.878507&amp;spn=0.006295,0.006295&amp;output=embed" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="425" height="350"></iframe><br />
<small><a style="color: #0000ff; text-align: left;" href="http://maps.google.fr/maps?f=q&amp;source=embed&amp;hl=fr&amp;geocode=&amp;q=Le+Shakespeare,+Rue+de+la+Petite+Loge,+Montpellier&amp;aq=1&amp;sll=46.75984,1.738281&amp;sspn=12.360483,19.753418&amp;ie=UTF8&amp;hq=Le+Shakespeare,&amp;hnear=Rue+de+la+Petite+Loge,+34000+Montpellier,+H%C3%A9rault,+Languedoc-Roussillon&amp;ll=43.610598,3.878507&amp;spn=0.006295,0.006295">Agrandir le plan</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/lexik-life/symfony2-launch-party-a-montpellier-1655/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enfin un design pour le blog Lexik</title>
		<link>http://www.lexik.fr/blog/symfony/lexik-life/enfin-un-design-pour-le-blog-lexik-1586</link>
		<comments>http://www.lexik.fr/blog/symfony/lexik-life/enfin-un-design-pour-le-blog-lexik-1586#comments</comments>
		<pubDate>Mon, 18 Jul 2011 16:48:27 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Lexik Life]]></category>
		<category><![CDATA[lexik]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1586</guid>
		<description><![CDATA[Après 2 ans et demi de bons et loyaux services, le thême trouvé rapidement sur internet s&#8217;en est allé et laisse place à une version plus personnelle de l&#8217;équipe de développement. Retrouvez nos développeurs Symfony cachés entre des div et &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/lexik-life/enfin-un-design-pour-le-blog-lexik-1586">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Après 2 ans et demi de bons et loyaux services, le thême trouvé rapidement sur internet s&#8217;en est allé et laisse place à une version plus personnelle de l&#8217;équipe de développement.</p>
<p>Retrouvez nos développeurs Symfony cachés entre des div et des h<code>n</code>.<span id="more-1586"></span></p>
<h2>Quoi de neuf chez Lexik ?</h2>
<ul>
<li>un nouveau logo ;</li>
<li>des projets Symfony2 ;</li>
<li>de nouveaux développeurs ;</li>
<li>un championnat de pétanque tout l&#8217;été ;</li>
<li>des applications mobiles pour le blog.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/lexik-life/enfin-un-design-pour-le-blog-lexik-1586/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Offre d&#8217;emploi développeur PHP / Symfony</title>
		<link>http://www.lexik.fr/blog/symfony/recrutement/offre-d-emploi-developpeur-php-symfony-1562</link>
		<comments>http://www.lexik.fr/blog/symfony/recrutement/offre-d-emploi-developpeur-php-symfony-1562#comments</comments>
		<pubDate>Wed, 20 Apr 2011 11:51:10 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Lexik Life]]></category>
		<category><![CDATA[recrutement]]></category>
		<category><![CDATA[developpeur]]></category>
		<category><![CDATA[emploi]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1562</guid>
		<description><![CDATA[Lexik est une agence Web spécialisée dans le développement d&#8217;application Web et de sites Internet sur-mesure en PHP avec le framework Symfony. Nous souhaitons renforcer nos équipes de développement par 2 développeurs pour nos projets clients et internes. Vous avez &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/recrutement/offre-d-emploi-developpeur-php-symfony-1562">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Lexik est une agence Web spécialisée dans le développement d&#8217;application Web et de sites Internet sur-mesure en PHP avec le framework Symfony. Nous souhaitons renforcer nos équipes de développement par <strong>2 développeurs</strong> pour nos projets clients et internes. Vous avez envie de vous intégrer dans une jeune société (âge moyen : entre 25 et 30 ans) avec <strong>une ambiance agréable et dynamique</strong>, de travailler en équipe sous la responsabilité d&#8217;un chef de projet.<br />
<span id="more-1562"></span></p>
<h2>Votre profil :</h2>
<p>De formation BTS / DUT ou école d&#8217;ingénieur, vous justifiez <strong>d&#8217;une expérience significative</strong> dans le milieu du développement Web.</p>
<p>Vous bénéficiez d&#8217;une bonne expérience à titre privé ou professionnel dans les technologies suivantes :</p>
<ul>
<li>XHTML / CSS ;</li>
<li>PHP 5, orienté objet ;</li>
<li>SQL (MySQL, SQLite, PostgreSQL, &#8230;).</li>
</ul>
<p>Une expérience ou un intérêt dans les domaines suivants seront un atout :</p>
<ul>
<li>Framework symfony 1.4 / Symfony2 avec l&#8217;ORM Doctrine ;</li>
<li>Gestionnaire de version (Git / SVN) ;</li>
<li>Javascript ;</li>
<li>Tests unitaires et fonctionnels / Intégration continue ;</li>
<li>Méthodologie de développement agile (SCRUM).</li>
</ul>
<h2>Détails :</h2>
<p><strong>Envoyez-nous votre CV et lettre de motivation par email à l&#8217;adresse : <a href="mailto:contact@lexik.fr">contact@lexik.fr</a></strong></p>
<ul>
<li>Type de contrat : CDI</li>
<li>Lieu : Pérols</li>
<li>Début du contrat : ASAP</li>
<li>Télétravail : non</li>
<li>Rémunération selon profil</li>
</ul>
<p><a href="http://www.lexik.fr/">http://www.lexik.fr/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/recrutement/offre-d-emploi-developpeur-php-symfony-1562/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utilisation de l&#8217;event dispatcher depuis les classes du modèle.</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/utilisation-de-levent-dispatcher-depuis-les-classes-du-modele-1337</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/utilisation-de-levent-dispatcher-depuis-les-classes-du-modele-1337#comments</comments>
		<pubDate>Mon, 20 Dec 2010 09:17:03 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.4.x]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[event dispatcher]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1337</guid>
		<description><![CDATA[Le but de cet article n&#8217;est pas d&#8217;expliquer le fonctionnement des événements symfony, la documentation officielle est très bien faite à ce sujet, et pas mal d&#8217;articles expliquant leur implementation existent déjà. Le but est juste de savoir comment faire &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/utilisation-de-levent-dispatcher-depuis-les-classes-du-modele-1337">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Le but de cet article n&#8217;est pas d&#8217;expliquer le fonctionnement des événements symfony, <a href="http://www.symfony-project.org/reference/1_4/fr/15-Events" target="_blank">la documentation officielle</a> est très bien faite à ce sujet, et pas mal d&#8217;articles expliquant leur implementation existent déjà.</p>
<p>Le but est juste de savoir comment faire pour avoir accès à l&#8217;event dispatcher depuis les classes du modèle, de manière à pouvoir lever des événements &laquo;&nbsp;métiers&nbsp;&raquo; qui permettent des traitements qui se rapprochent des trigger sql. L&#8217;avantage est de rester au sein de l&#8217;application symfony et ne pas disperser la logique. C&#8217;est une problèmatique que nous avons rencontré à plusieurs reprises dans les projets et nous avons pu trouver cette implementation grace à n1k0 de chez <a href="http://www.akei.com/fr" target="_blank">Akei</a>.</p>
<p><span id="more-1337"></span></p>
<p>(Pour la suite, je vais me servir d&#8217;une partie du modèle de Jobeet comme je l&#8217;avais fait dans <a href="http://www.lexik.fr/blog/symfony/symfony/qui-leu-crud-ou-comment-creer-un-theme-pour-les-crud-doctrine-de-symfony-1181">mon post précédent</a>)</p>
<p>A la base, l&#8217;event dispatcher se trouve dans le contexte, et donc accessible principalement depuis les actions des modules. L&#8217;idée est de le rendre accessible aux classes du modèle doctrine de manière à pouvoir notifier des événements &laquo;&nbsp;métier&nbsp;&raquo; directement depuis les méthodes. On va donc passer l&#8217;event dispatcher à la classe de base dont hérite toutes les classes du modèle. Ou plus exactement, on va rajouter une classe custom dans la pile d&#8217;héritage des classes du modèle.</p>
<p>On créé donc une classe CustomDoctrineRecord, que je place dans /lib/model/doctrine/record/CustomDoctrineRecord.class.php pour éviter qu&#8217;elle se retrouve noyée avec les classes du modèle. On va faire passer à cette classe l&#8217;event dispatcher par des méthodes statiques.<br />
Les classes de base du modèle héritent de sfDoctrineRecord, il faut donc impérativement que la classe custom hérite elle aussi de sfDoctrineRecord.</p>
<p>Fichier : /lib/model/doctrine/record/CustomDoctrineRecord.class.php</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('p1337code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13377"><td class="code" id="p1337code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> CustomDoctrineRecord <span style="color: #000000; font-weight: bold;">extends</span> sfDoctrineRecord
<span style="color: #009900;">&#123;</span>
  static <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$dispatcher</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Sets the EventDispatcher
   *
   * @param sfEventDispatcher $dispatcher 
   */</span>
  static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setEventDispatcher<span style="color: #009900;">&#40;</span>sfEventDispatcher <span style="color: #000088;">$dispatcher</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$dispatcher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dispatcher</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Returns the EventDispatcher
   *
   * @return sfEventDispatcher
   */</span>
  static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getEventDispatcher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$dispatcher</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Returns if EventDispatcher is available
   *
   * @return boolean
   */</span>
  static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasDispatcher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getEventDispatcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> instanceOf sfEventDispatcher<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>

<p>Maintenant il faut spécifier à doctrine d&#8217;utiliser notre classe custom comme classe de référence des classes modèles, on utilise la méthode configureDoctrine() de sfProjectConfiguration. Aprés quoi on va avoir besoin de passer l&#8217;event dispatcher à notre classe. On va donc catcher l&#8217;événement &laquo;&nbsp;context.load_factories&nbsp;&raquo; qui est déclenché une fois que le contexte est initialisé pour aller initialiser la classe CustomDoctrineRecord.</p>
<p>Fichier : /config/ProjectConfiguration.class.php</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('p1337code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13378"><td class="code" id="p1337code8"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php'</span><span style="color: #339933;">;</span>
sfCoreAutoload<span style="color: #339933;">::</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ProjectConfiguration <span style="color: #000000; font-weight: bold;">extends</span> sfProjectConfiguration
<span style="color: #009900;">&#123;</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>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enablePlugins</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;">'sfDoctrinePlugin'</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatcher</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'context.load_factories'</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: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'listenToContextFactoriesLoaded'</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: #009933; font-style: italic;">/**
   * Defines the base objects' classe
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configureDoctrine<span style="color: #009900;">&#40;</span>Doctrine_Manager <span style="color: #000088;">$manager</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'doctrine_model_builder_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: #0000ff;">'baseClassName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'CustomDoctrineRecord'</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: #009933; font-style: italic;">/**
   * Objects can acces the EventDispatcher
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listenToContextFactoriesLoaded<span style="color: #009900;">&#40;</span>sfEvent <span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    CustomDoctrineRecord<span style="color: #339933;">::</span><span style="color: #004000;">setEventDispatcher</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSubject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEventDispatcher</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Aprés ca, il nous reste à faire un petit</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('p1337code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p13379"><td class="code" id="p1337code9"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">./</span>symfony doctrine<span style="color: #339933;">:</span>build <span style="color: #339933;">--</span>all<span style="color: #339933;">-</span>classes</pre></td></tr></table></div>

<p>Et on peut vérifier l&#8217;inpact en ouvrant une classe de base, et on trouve bien que la classe hérite de notre classe CustomDoctrineRecord</p>
<p>Fichier : /lib/model/doctrine/base/BaseJobeetJob.class.php</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('p1337code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p133710"><td class="code" id="p1337code10"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #339933;">...</span>
abstract <span style="color: #000000; font-weight: bold;">class</span> BaseJobeetJob <span style="color: #000000; font-weight: bold;">extends</span> CustomDoctrineRecord
<span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span></pre></td></tr></table></div>

<p>Il est donc maintenant possible de lever des événements depuis les classes du modèle. Pour exemple je vais lever un événement à l&#8217;insertion d&#8217;un nouveau Job. Cet événement pourra être utilisé par la suite pour faire ce que l&#8217;on veut, comme par exemple envoyer une email au modèrateur l&#8217;informant qu&#8217;un nouveau job a été saisi sur le site.</p>
<p>Fichier : /lib/model/doctrine/JobeetJob.class.php</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('p1337code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p133711"><td class="code" id="p1337code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> JobeetJob <span style="color: #000000; font-weight: bold;">extends</span> BaseJobeetJob
<span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * @param Doctrine_Event $event 
   */</span>
  <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><span style="color: #000088;">$event</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">hasDispatcher</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getEventDispatcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasListeners</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JobeetJob.Inserted'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">getEventDispatcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">notify</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfEvent<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'JobeetJob.Inserted'</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>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>C&#8217;est un exemple tout simple, mais les possibilités sont immenses. Attention aux événements en cascades, ca peut très vite devenir un casse tête à debugger !</p>
<p>Dernier petit tips, pour pouvoir faire des tests de vos méthodes qui lèvent des événements : c&#8217;est à mis chemin entre les tests unitaires et les tests fonctionnels. J&#8217;ai voulu tester des enchainements de méthodes qui levaient des événements, et je voulais vérifier que les règles de gestion étaient respectées. Je suis donc parti du bootstap unitaire où j&#8217;ai initialisé un contexte que je passe à ma classe de base, de manière à ce que les événements soient diffusés.</p>
<p>Fichier : /test/bootstrap/unit_event.php</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('p1337code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p133712"><td class="code" id="p1337code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/unit.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$configuration</span> <span style="color: #339933;">=</span> ProjectConfiguration<span style="color: #339933;">::</span><span style="color: #004000;">getApplicationConfiguration</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frontend'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> sfContext<span style="color: #339933;">::</span><span style="color: #004000;">createInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$configuration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
CustomDoctrineRecord<span style="color: #339933;">::</span><span style="color: #004000;">setEventDispatcher</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$configuration</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getEventDispatcher</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Quand on commence à utiliser les événements, il y a deux réactions possibles. Il y a les réfractaires qui disent &laquo;&nbsp;c&#8217;est null, ca sert a rien&nbsp;&raquo;, soit on devient accro et on commence à en mettre de partout. Si vous faites parti du deuxième groupe, voici quelques conseils élémentaires mais important à respecter pour éviter que le debuggage se transforme en calvaire :</p>
<ul>
<li>mettre des noms d&#8217;événements explicites ;</li>
<li>centraliser les écouteurs.</li>
</ul>
<p>Bon codage à tous, et bonnes fêtes <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/utilisation-de-levent-dispatcher-depuis-les-classes-du-modele-1337/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Développeur Web Symfony Montpellier</title>
		<link>http://www.lexik.fr/blog/symfony/non-classe/travailler-chez-lexik-developpeur-web-symfony-1069</link>
		<comments>http://www.lexik.fr/blog/symfony/non-classe/travailler-chez-lexik-developpeur-web-symfony-1069#comments</comments>
		<pubDate>Fri, 26 Feb 2010 10:41:35 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Non classé]]></category>
		<category><![CDATA[developpeur]]></category>
		<category><![CDATA[montpellier]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1069</guid>
		<description><![CDATA[Lexik est une société spécialisée dans le développement Symfony et la conception de solutions orientées web. Sous la responsabilité d&#8217;un chef de projet technique, au sein d&#8217;une équipe de développeurs, vous aurez à charge de concevoir et de développer des &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/non-classe/travailler-chez-lexik-developpeur-web-symfony-1069">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Lexik est une société spécialisée dans le développement Symfony et la conception de solutions orientées web.<br />
Sous la responsabilité d&#8217;un chef de projet technique, au sein d&#8217;une équipe de développeurs, vous aurez à charge de concevoir et de développer des solutions Intranet / Internet.</p>
<p>De formation initiale informatique (de bac à +5), vous êtes un développeur confirmé en PHP/MySQL (environnement LAMP et WAMP) avec une expérience d&#8217;au moins 1 ans au sein d&#8217;une SSII ou d&#8217;une web agency.</p>
<p>Compétences requises :<br />
- Framework PHP Symfony<br />
- bonnes connaissances des environnements WAMP (Windows) et LAMP<br />
- MySQL et SQL<br />
- PHP (programmation objet)<br />
- (X)HTML, DHTML , JavaScript, CSS.<br />
- AJAX<br />
- Javascript, jQuery<br />
- standards du web (W3C)<br />
- Connaissance de subversion</p>
<p>Qualités recherchées :<br />
- curiosité<br />
- force de proposition<br />
- sens du travail en équipe</p>
<p>Disponibilité :<br />
- ASAP</p>
<p>Poste à Montpellier 34000</p>
<p>Contactez Samuel Breton, Tél : 04 67 99 63 19<br />
Email : contact@lexik.fr<br />
CV + LM </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/non-classe/travailler-chez-lexik-developpeur-web-symfony-1069/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tips : Symfony 1.3/1.4 orderBy des relations</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/tips-symfony-1-31-4-orderby-des-relations-1026</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/tips-symfony-1-31-4-orderby-des-relations-1026#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:11:27 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.3.x]]></category>
		<category><![CDATA[1.4.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[orderBy]]></category>
		<category><![CDATA[relation]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1026</guid>
		<description><![CDATA[Depuis la branche 1.3/1.4 la gestion des relations a été bien enrichie. Au niveau des formulaire l'apparition du EmbedRelation a vraiment facilité l'implémentation des embedForm. Petit problème, l'ordre de retour de la Doctrine_Collection ...<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/tips-symfony-1-31-4-orderby-des-relations-1026">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Depuis la branche 1.3/1.4 la gestion des relations a été bien enrichie.</p>
<p>Au niveau des formulaire l&#8217;apparition du EmbedRelation a vraiment facilité l&#8217;implémentation des embedForm. Je ne vais pas reprendre l&#8217;explication de cette fonctionnalité dans cet article et vous renvoie donc vers le très bon article de NiKo <a href="http://prendreuncafe.com/blog/post/2009/11/29/Embedding-Relations-in-Forms-with-Symfony-1.3-and-Doctrine" target="_blank">sur son blog</a> (En anglais).</p>
<p>Petit problème, l&#8217;ordre de tri de la Doctrine_Collection retrounée qui est &#8230;<span id="more-1026"></span> en vrac ^^ J&#8217;en ai fait l&#8217;expérience sur une base postGre ou l&#8217;ordre de retour est en fonction de la dernière modification alors que sur une base mySql c&#8217;est l&#8217;ordre des IDs (déjà moins gênant). Dans les 2 cas ça n&#8217;est pas très satisfaisant, et on aimerais pouvoir maitriser l&#8217;ordre de tri de cette relation.</p>
<p>Un bout de schema.yml pour pouvoir illustrer mon explication  :</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('p1026code13'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p102613"><td class="code" id="p1026code13"><pre class="yml" style="font-family:monospace;">...
Produit:
  columns:
    id:                 { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    name:               { type: string(128), notnull: true }
&nbsp;
Photo:
  columns:
    id:                 { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    file_name:          { type: string(128), notnull: true }
    id_produit:         { type: integer(4), unsigned: true }
    ordre:              { type: integer(4), unsigned: true }
  relations:
    Produit:
      local:            id_produit
      foreign:          id
      foreignAlias:     Photos
      onDelete:         CASCADE
...</pre></td></tr></table></div>

<p>Dans ce contexte on peut imaginer faire un EmbedRelation des Photos dans la classe ProduitForm.</p>
<p>Le fonctionnement du EmbedRelation est qu&#8217;il utilise l&#8217;accesseur magique getPhotos() qui elle même fait un findByIdProduit() dans la classe PhotoTable et retourne une Doctrine_Collection d&#8217;objects Photo. Seul problème comme je l&#8217;ai dit plus haut, c&#8217;est que la requête n&#8217;est pas trié.</p>
<p>Vous allez me dire &laquo;&nbsp;c&#8217;est facile, il n&#8217;y a qu&#8217;à surcharger getPhotos() de Produit.class.php&nbsp;&raquo;. C&#8217;est ce que j&#8217;avais fait au début, et ça marche. Seul problème, c&#8217;est que lorsque l&#8217;on redéfini un accesseur magique (ici le getteur) l&#8217;autre (le setteur) ne fonctionne plus&#8230; est ce que c&#8217;est voulu ou est ce que c&#8217;est un bug? Je n&#8217;en sais rien ^^ Toujours est-il que je me servais du setteur et donc cette solution ne m&#8217;a pas convenu et j&#8217;ai cherché une alternative.</p>
<p>L&#8217;alternative est prévue par Doctrine qui depuis la 1.2 qui implémente la possibilité de spécifier le orderBy sur une relation directement lors de sa définition dans le schema.yml. Seul problème le foreinOrderBy n&#8217;existe pas et donc la définition de la relation ne peut plus se faire comme je l&#8217;avais écrite plus haut, il faut la définir des deux cotés.</p>
<p>Tréve de blabla, ca ressemble à quelque chose comme ca :</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('p1026code14'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p102614"><td class="code" id="p1026code14"><pre class="yml" style="font-family:monospace;">...
Produit:
  columns:
    id:                 { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    name:               { type: string(128), notnull: true }
  relations:
    Photos:
      type:             many
      class:            Photo
      local:            id
      foreign:          id_produit
      orderBy:          ordre ASC
      onDelete:         CASCADE
&nbsp;
Photo:
  columns:
    id:                 { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    file_name:          { type: string(128), notnull: true }
    id_produit:         { type: integer(4), unsigned: true }
    ordre:              { type: integer(4), unsigned: true }
  relations:
    Produit:
      local:            id_produit
      foreign:          id
      onDelete:         CASCADE
...</pre></td></tr></table></div>

<p>J&#8217;espère que cette petite astuce vous aidera.<br />
@bientôt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/tips-symfony-1-31-4-orderby-des-relations-1026/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Gestion d&#8217;une galerie photo avec swfUpload dans l&#8217;admin</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/gestion-dune-galerie-photo-avec-swfupload-dans-ladmin-918</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/gestion-dune-galerie-photo-avec-swfupload-dans-ladmin-918#comments</comments>
		<pubDate>Wed, 16 Sep 2009 08:49:18 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Admingenerator 1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[admin generator]]></category>
		<category><![CDATA[swfUpload]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=918</guid>
		<description><![CDATA[Je vous propose de voir une gestion de galerie photo pour l'administration, telle que je l'ai abordée dans un de mes derniers projets.
C'est à dire avec swfUpload et en ajax dans l'admin generator.<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/gestion-dune-galerie-photo-avec-swfupload-dans-ladmin-918">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Je vous propose de voir une gestion de galerie photo pour l&#8217;administration, telle que je l&#8217;ai abordée dans un de mes derniers projets.</p>
<p>Pour vous situer, il s&#8217;agit d&#8217;un site de vente en ligne.<br />
Qui dit vente dit produits, et qui dit produits dit photos <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
<span id="more-918"></span><br />
L&#8217;idée est de gérer les photos d&#8217;un produit directement depuis sa page d&#8217;édition de l&#8217;admin générator.</p>
<p><img src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2009/09/upload1-300x99.png" alt="upload1" title="upload1" width="300" height="99" class="alignnone size-medium wp-image-921" /></p>
<p><img src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2009/09/upload2-300x184.png" alt="upload2" title="upload2" width="300" height="184" class="alignnone size-medium wp-image-922" /></p>
<p><img src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2009/09/upload3-300x178.png" alt="upload3" title="upload3" width="300" height="178" class="alignnone size-medium wp-image-923" /></p>
<p>On a choisi de gérer l&#8217;upload avec swfUpload qui gére un liste d&#8217;attente pour l&#8217;upload de plusieurs fichiers. Et l&#8217;upload en background qui ne gèle pas la page, ca fait plus web2.0 :p<br />
(<a href="http://code.google.com/p/swfupload/" tager="_blank">http://code.google.com/p/swfupload/</a>)</p>
<p>J&#8217;ai téléchargé le <a href="http://swfupload.googlecode.com/files/SWFUpload%20v2.2.0.1%20Samples.zip" target="_blank">SWFUpload v2.2.0.1 Samples.zip</a> et j&#8217;ai utilisé les fichiers du répertoire &laquo;&nbsp;simpledemo&nbsp;&raquo; que j&#8217;ai réparties comme suis.<br />
(Le fichier css d&#8217;origine s&#8217;appelait default.css, je l&#8217;ai renommé pour des raisons évidentes.)</p>
<ul>
<li>/web/swf/swfupload.swf</li>
<li>/web/css/swfUpload.css</li>
<li>/web/js/swfupload.js</li>
<li>/web/js/swfupload.queue.js</li>
<li>/web/js/fileprogress.js</li>
<li>/web/js/handlers.js</li>
<li>/web/images/XPButtonUploadText_61x22.png</li>
</ul>
<p>Un coup d&#8217;oeil rapide à la partie du schema.yml qui nous intéresse. Rien de transcendant, un objet Produit avec quelques champs types et l&#8217;objet ProduitPhoto qui lui est lié. Sur l&#8217;objet ProduitPhoto, un filename et un booléen pour définir l&#8217;image  par défaut du produit.</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('p918code15'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91815"><td class="code" id="p918code15"><pre class="yml" style="font-family:monospace;">...
Produit:
  tableName:        monprojet_produit
  actAs:
    Timestampable:  ~
  columns:
    id:             { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    nom:            { type: string(255), notnull: true }
    description:    { type: clob }
    prix:           { type: decimal, scale: 2 }
&nbsp;
ProduitPhoto:
  tableName:        monprojet_produit_photo
  columns:
    id:             { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    produit_id:     { type: integer(4), unsigned: true }
    filename:       { type: string(255), notnull: true }
    is_default:     { type: boolean, default: false }
  relations:
    Produit:
      local:        produit_id
      foreign:      id
      foreignAlias: Photos
      onDelete:     CASCADE
...</pre></td></tr></table></div>

<p>On génére l&#8217;admin-generator pour l&#8217;objet produit.</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('p918code16'); return false;">View Code</a> CONSOLE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91816"><td class="code" id="p918code16"><pre class="console" style="font-family:monospace;">./symfony doctrine:generate-admin backend Produit</pre></td></tr></table></div>

<p>Et c&#8217;est partie !</p>
<p>Pour rajouter cette gestion des images dans l&#8217;ecran d&#8217;édition des produits il faut rajouter un partial à la vue edit.<br />
(On la rajoute uniquement sur l&#8217;edit, car sur l&#8217;écran create, l&#8217;objet n&#8217;est pas encore persisté en base et donc on ne peut pas lui rattacher des objets ProduitPhoto)</p>
<p>Le fonctionnement est le suivant. Le partial général où est inclus et configuré swfUpload (_photoUpload.php). Un parial _photoListe.php inclus dans _photoUpload.php qui servira pour raffraichir la liste en ajax (avec jQuery). Et un dernier partial _ajaxPhotoDelete.php qui ne sert qu&#8217;a retourner l&#8217;animation à faire lors de la suppression d&#8217;une photo.</p>
<p>On commence par positionner le partial _photoUpload.php dans le generator.yml en contexte edit.</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('p918code17'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91817"><td class="code" id="p918code17"><pre class="yml" style="font-family:monospace;">generator:
  class: sfDoctrineGenerator
  param:
    model_class:           Produit
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          produit_produit
    with_doctrine_route:     1
&nbsp;
    config:
      actions: ~
      fields:
        created_at:        { label: Date de création, date_format: dd/MM/yyyy }
        updated_at:        { label: Date de modification, date_format: dd/MM/yyyy }
        nom:               { label: Nom }
        description:       { label: Déscription }
      list:
        title:             Liste des produits
        display:           [=id, =nom]
      filter: ~
      form: ~
      edit:
        title:             Modifier un produit
        display:
          &quot;Produit&quot;:       [id, nom, description]
          &quot;Photos&quot;:        [_photoUpload]
          &quot;Dates&quot;:         [created_at, updated_at]
      new:
        title:             Ajouter un produit
        display:
          &quot;Produit&quot;:       [id, nom, description]
          &quot;Dates&quot;:         [created_at, updated_at]</pre></td></tr></table></div>

<p>Et on va se pencher plus en détail sur ce partial _photoUpload.php.</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('p918code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91818"><td class="code" id="p918code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> use_stylesheet<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'swfUpload.css'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'swfupload.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'swfupload.queue.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fileprogress.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'handlers.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pictures_list&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_form_row&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> include_partial<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'produit/photoListe'</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;">'photos'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotos</span><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: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;picture_upload&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_form_row&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fieldset flash&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;fsUploadProgress&quot;</span><span style="color: #339933;">&gt;&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;legend&quot;</span><span style="color: #339933;">&gt;</span>File d<span style="color: #0000ff;">'attente.&lt;/span&gt;&lt;/div&gt;
  &lt;div id=&quot;divStatus&quot;&gt;0 fichier uploadé.&lt;/div&gt;
  &lt;div&gt;
    &lt;span id=&quot;spanButtonPlaceHolder&quot;&gt;&lt;/span&gt;
    &lt;input id=&quot;btnCancel&quot; type=&quot;button&quot; value=&quot;Cancel All Uploads&quot; onclick=&quot;$.swfUpload.cancelQueue();&quot; disabled=&quot;disabled&quot; style=&quot;margin-left: 2px; font-size: 8pt; height: 29px;&quot; /&gt;
  &lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;
(function($) {
&nbsp;
  $('</span>div<span style="color: #339933;">.</span>actions a<span style="color: #339933;">.</span><span style="color: #b1b100;">default</span><span style="color: #0000ff;">').live('</span>click<span style="color: #0000ff;">', function(event) {
    event.preventDefault();
    $.post(
      $(this).attr('</span>href<span style="color: #0000ff;">'),
      { },
      function(data) {
        $('</span><span style="color: #666666; font-style: italic;">#pictures_list').html(data);
</span>      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'div.actions a.delete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>live<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'click'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    event<span style="color: #339933;">.</span>preventDefault<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>confirm<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Etes vous sur de vouloir supprimer cette photo ?'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #339933;">.</span>post<span style="color: #009900;">&#40;</span>
        $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <a href="http://www.php.net/eval"><span style="color: #990000;">eval</span></a><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  myQueueComplete <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>numFilesUploaded<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> status <span style="color: #339933;">=</span> document<span style="color: #339933;">.</span>getElementById<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;divStatus&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    status<span style="color: #339933;">.</span>innerHTML <span style="color: #339933;">=</span> numFilesUploaded <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; fichier&quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>numFilesUploaded <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; uploadé&quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>numFilesUploaded <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;s&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #339933;">.</span>post<span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'&lt;?php echo url_for('</span>produit_ajax_photo_liste<span style="color: #0000ff;">', $form-&gt;getObject()) ?&gt;'</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#pictures_list'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  jQuery<span style="color: #339933;">.</span>swfUpload <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SWFUpload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    flash_url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;/swf/swfupload.swf&quot;</span><span style="color: #339933;">,</span>
    upload_url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&lt;?php echo url_for('produit_photo', <span style="color: #006699; font-weight: bold;">$form-&gt;getObject</span>()) ?&gt;&quot;</span><span style="color: #339933;">,</span>
    post_params<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;&lt;?php echo ini_get('session.name') ?&gt;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&lt;?php echo session_id(); ?&gt;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    file_size_limit<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;100 MB&quot;</span><span style="color: #339933;">,</span>
    file_types<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;*.jpg;*.gif;*.png&quot;</span><span style="color: #339933;">,</span>
    file_types_description<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Fichiers image&quot;</span><span style="color: #339933;">,</span>
    file_upload_limit<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span>
    file_queue_limit<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
    file_post_name<span style="color: #339933;">:</span> <span style="color: #0000ff;">'photo'</span><span style="color: #339933;">,</span>
    custom_settings<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
      progressTarget<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;fsUploadProgress&quot;</span><span style="color: #339933;">,</span>
      cancelButtonId<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;btnCancel&quot;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    debug<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">// Button settings</span>
    button_image_url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;/images/XPButtonUploadText_61x22.png&quot;</span><span style="color: #339933;">,</span>
    button_width<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;61&quot;</span><span style="color: #339933;">,</span>
    button_height<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;22&quot;</span><span style="color: #339933;">,</span>
    button_placeholder_id<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;spanButtonPlaceHolder&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">// The event handler functions are defined in handlers.js</span>
    file_queued_handler<span style="color: #339933;">:</span> fileQueued<span style="color: #339933;">,</span>
    file_queue_error_handler<span style="color: #339933;">:</span> fileQueueError<span style="color: #339933;">,</span>
    file_dialog_complete_handler<span style="color: #339933;">:</span> fileDialogComplete<span style="color: #339933;">,</span>
    upload_start_handler<span style="color: #339933;">:</span> uploadStart<span style="color: #339933;">,</span>
    upload_progress_handler<span style="color: #339933;">:</span> uploadProgress<span style="color: #339933;">,</span>
    upload_error_handler<span style="color: #339933;">:</span> uploadError<span style="color: #339933;">,</span>
    upload_success_handler<span style="color: #339933;">:</span> uploadSuccess<span style="color: #339933;">,</span>
    upload_complete_handler<span style="color: #339933;">:</span> uploadComplete<span style="color: #339933;">,</span>
    queue_complete_handler<span style="color: #339933;">:</span> myQueueComplete
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Il faut penser à inclure les différents éléments nécessaires le css et les tout les js. Je les ai inclus ici pour bien les mettre en évidence.<br />
Après il suffit de positionner les différents éléments html nécessaires au fonctionnement de swfUpload.<br />
Et enfin le javascript pour initialiser swfUpload. J&#8217;utilise jQuery pour gérer l&#8217;ajax, j&#8217;ai donc adapté l&#8217;initialisation de swfUpload pour la rendre &laquo;&nbsp;jQuery friendly&nbsp;&raquo; :p</p>
<p>L&#8217;initialisation de swfUpload est assez standard, avec toute une tripoté de paramètres pour définir : le type de fichier accepté, configurer l&#8217;apparence du bouton et configurer tous les retour d&#8217;événements qu&#8217;il est possible d&#8217;utiliser.<br />
J&#8217;ai laissé les gestionnaires d&#8217;événements par défaut à l&#8217;exception de l&#8217;événement de fin d&#8217;upload (myQueueComplete) que j&#8217;ai redéfini pour faire un appel ajax et recharger le partial _photoListe.php.<br />
J&#8217;attire votre attention sur le parametre post_params auquel on passe le session name et le session_id, on verra un peu plus bas le pourquoi du comment <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Le partial _photoListe.php, rien de spécial. Un listing des photos du produit avec 2 liens pour supprimer ou définir comme image par défaut, les 2 faisant appel à une action en ajax.<br />
(NB: On retrouve <a href="http://www.lexik.fr/blog/symfony/symfony/generer-des-thumbs-lors-de-laffichage-dune-image-781" target="_blank">le Helper Thumb de thomas</a> pour les miniatures des photos)</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('p918code19'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91819"><td class="code" id="p918code19"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> use_helper<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Thumb'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<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;">$photos</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&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;">$photos</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$photo</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>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;photo-&lt;?php echo <span style="color: #006699; font-weight: bold;">$photo-&gt;getId</span>()?&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;picture&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> showThumb<span style="color: #009900;">&#40;</span>
  <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFilename</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'produits'</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;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'width'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'alt'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProduit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'title'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProduit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNom</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'border'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'center'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'produit-defaut.jpg'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;actions&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;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isDefault</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>strong<span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/images/backend/star.png&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span> <span style="color: #339933;">/&gt;</span> Par défaut<span style="color: #339933;">&lt;/</span>strong<span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</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: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo url_for('produit_photo_ajax_default', <span style="color: #006699; font-weight: bold;">$photo</span>) ?&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;default&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/images/backend/star.png&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span> <span style="color: #339933;">/&gt;</span> Par défaut<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo url_for('produit_photo_ajax_delete', <span style="color: #006699; font-weight: bold;">$photo</span>) ?&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;delete&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/images/backend/cross.png&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span> <span style="color: #339933;">/&gt;</span> Supprimer<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&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>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<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>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;clear&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Aucune photo pour l<span style="color: #0000ff;">'instant.&lt;/p&gt;
&lt;?php endif; ?&gt;</span></pre></td></tr></table></div>

<p>Le partial _ajaxPhotoDelete.php, c&#8217;est juste l&#8217;effet jQuery-ui pour faire disparaitre la div de la photo qui viens d&#8217;être supprimée.</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('p918code20'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91820"><td class="code" id="p918code20"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#photo-&lt;?php echo $photo_id ?&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">effect</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'drop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Un petit tour sur le routing.yml pour défnir les différentes routes utilisées.</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('p918code21'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91821"><td class="code" id="p918code21"><pre class="yml" style="font-family:monospace;">...
produit_photo:
  url:     /produit/:id/upload
  class:   sfDoctrineRoute
  options: { model: Produit, type: object }
  param:   { module: produit, action: upload }
  requirements:
    sf_method: [get, post]
&nbsp;
produit_photo_ajax_default:
  url:     /produit_photo/:id/default
  class:   sfDoctrineRoute
  options: { model: ProduitPhoto, type: object }
  param:   { module: produit, action: ajaxPhotoDefault }
  requirements:
    sf_method: [post]
&nbsp;
produit_photo_ajax_delete:
  url:     /produit_photo/:id/delete
  class:   sfDoctrineRoute
  options: { model: ProduitPhoto, type: object }
  param:   { module: produit, action: ajaxPhotoDelete }
  requirements:
    sf_method: [post]
&nbsp;
produit_ajax_photo_liste:
  url:     /produit_photo/:id/list
  class:   sfDoctrineRoute
  options: { model: Produit, type: object }
  param:   { module: produit, action: ajaxPhotoListe }
  requirements:
    sf_method: [post]
...</pre></td></tr></table></div>

<p>On utilise la classe formulaire qui va gérer l&#8217;upload.<br />
Il faut désactiver le csrf car l&#8217;envoie n&#8217;est pas effectué par le formulaire mais par l&#8217;animation flash.</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('p918code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91822"><td class="code" id="p918code22"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ProduitPhotoForm <span style="color: #000000; font-weight: bold;">extends</span> BaseProduitPhotoForm
<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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'produit_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_default'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filename'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputFile<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: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filename'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorFile<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: #339933;">,</span>
      <span style="color: #0000ff;">'path'</span>       <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_upload_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/produits/source'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'mime_types'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'web_images'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'max_size'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10485760</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;">'max_size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Fichier trop gros (10Mo maximum).'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disableCSRFProtection</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></pre></td></tr></table></div>

<p>Et enfin l&#8217;action.class.php qui orchestre tout ca.<br />
Au niveau de l&#8217;action executeUpload il faut créer &laquo;&nbsp;à la main&nbsp;&raquo; le tableau des paramètres à passer au bind.</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('p918code23'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91823"><td class="code" id="p918code23"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../lib/produitGeneratorConfiguration.class.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <a href="http://www.php.net/dirname"><span style="color: #990000;">dirname</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../lib/produitGeneratorHelper.class.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * produit actions.
 *
 * @package    
 * @subpackage produit
 * @author     
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> produitActions <span style="color: #000000; font-weight: bold;">extends</span> autoProduitActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeUpload<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">produit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRoute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</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;">forward404unless</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">produit</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ProduitPhotoForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$values</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;">'produit_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">produit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'is_default'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">produit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'filename'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFiles</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$values</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <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;">form</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: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ok'</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;">$return</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ko'</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;">$return</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * ajax pour definir une photo par defaut
   *
   * @param sfWebRequest $request
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeAjaxPhotoDefault<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isXmlHttpRequest</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: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRoute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$produit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProduit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$old_default</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$produit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotoDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$produit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPhotoDefaut</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</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: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'produit/photoListe'</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;">'photos'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$produit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotos</span><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>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect404</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>
&nbsp;
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * ajax pour effacer une photo
   *
   * @param sfWebRequest $request
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeAjaxPhotoDelete<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isXmlHttpRequest</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: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRoute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$photo_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'produit/ajaxPhotoDelete'</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;">'photo_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$photo_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>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect404</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>
&nbsp;
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * ajax pour avoir la liste des photos
   *
   * @param sfWebRequest $request
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeAjaxPhotoListe<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isXmlHttpRequest</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: #000088;">$produit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRoute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'produit/photoListe'</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;">'photos'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$produit</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotos</span><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>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect404</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>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Produit.class.php</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('p918code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91824"><td class="code" id="p918code24"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Produit <span style="color: #000000; font-weight: bold;">extends</span> BaseProduit
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setPhotoDefaut<span style="color: #009900;">&#40;</span><span style="color: #000088;">$photoId</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    Doctrine_Query<span style="color: #339933;">::</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ProduitPhoto p'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p.is_default'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'?'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p.produit_id = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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>
&nbsp;
    Doctrine_Query<span style="color: #339933;">::</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ProduitPhoto p'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p.is_default'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'?'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">andWhere</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p.id = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$photoId</span><span style="color: #009900;">&#41;</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>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</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> getPhotoDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ProduitPhoto'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDefault</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</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: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ProduitPhotoTable.class.php</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('p918code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91825"><td class="code" id="p918code25"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ProduitPhotoTable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Table
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getDefault<span style="color: #009900;">&#40;</span><span style="color: #000088;">$produit_id</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'c'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">andWhere</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'c.produit_id = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$produit_id</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">andWhere</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'c.is_default = ?'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchOne</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ProduitPhoto.class.php</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('p918code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91826"><td class="code" id="p918code26"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ProduitPhoto <span style="color: #000000; font-weight: bold;">extends</span> BaseProduitPhoto
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>bool<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIsDefault</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: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Le problème !</h2>
<p>A ce stade, tout est fini et en place pour que ca marche. Hors ca ne marche pas&#8230; Pourquoi ? Je rapelle le contexte, on est dans l&#8217;admin donc on est identifié et c&#8217;est là le problème. En effet swfUpload est une animation flash contenu dans le page mais qui va initialiser des requêtes http parallèles à celle utilisée par le navigateur. Et donc lorsque swfUpload se pointe à l&#8217;url &laquo;&nbsp;produit_photo&nbsp;&raquo; pour initialisé son upload, il se prend une belle erreur 403&#8230;</p>
<p>Le problème est connu des concepteurs de swfUpload et la solutions qu&#8217;ils préconisent est de forcé l&#8217;identifiant de session dans le script d&#8217;upload en faisant un session_id($session_id). C&#8217;est pourquoi on le fait passer dans la variable &laquo;&nbsp;post_params&nbsp;&raquo; à l&#8217;initialisation de swfUpload.</p>
<p>Pour faire la même chose dans symfony on ne peut pas le faire dans une action, car la session est déjà initialisée à ce niveau. On est obligé d&#8217;aller modifié le factories.yml et la calsse la classe sfSessionStorage pour aller forcer l&#8217;identifiant de session dans le cas ou on fait appel à l&#8217;action upload.</p>
<p>C&#8217;est un tip que j&#8217;ai trouvé sur le <a href="http://forum.symfony-project.org/index.php/m/42999/" target="_blank">forum symfony</a> qui était pour la version 1.0, et qui fonctionne toujours à la différence que le contexte n&#8217;est plus passé en paramètre dans la 1.2 et donc il faut aller le charger.</p>
<p>factories.yml</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('p918code27'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91827"><td class="code" id="p918code27"><pre class="yml" style="font-family:monospace;">...
all:
...
  storage:
    class: mySessionStorage
    param:
      session_name: weezobackend
...</pre></td></tr></table></div>

<p>mySessionStorage.calss.php</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('p918code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91828"><td class="code" id="p918code28"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> mySessionStorage <span style="color: #000000; font-weight: bold;">extends</span> sfSessionStorage
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> initialize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$context</span> <span style="color: #339933;">=</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;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Shitty work-around for swfuploader</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;upload&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$sessionName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$parameters</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;session_name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$context</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: #000088;">$sessionName</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <a href="http://www.php.net/session_name"><span style="color: #990000;">session_name</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sessionName</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/session_id"><span style="color: #990000;">session_id</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    parent<span style="color: #339933;">::</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</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>

<p>Ça y est, cette fois ça marche !<br />
Et vous avez une gestion d&#8217;images directement dans la fiche du produit qui est assez user-friendly <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Merci d&#8217;avoir lu jusqu&#8217;au bout :p<br />
Je reste à votre disposition pour toute questions ou suggestions <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
@bientôt !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/gestion-dune-galerie-photo-avec-swfupload-dans-ladmin-918/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Du Javascript dynamique dans une vue en utilisant sf_format</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746#comments</comments>
		<pubDate>Wed, 08 Jul 2009 07:13:32 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sf_format]]></category>
		<category><![CDATA[vue]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=746</guid>
		<description><![CDATA[Il arrive que l&#8217;on ai besoin d&#8217;utiliser un script javascript spécifique dans une vue. Un script dynamique qui nécessite d&#8217;être renseigné par des informations de php (utiliser des variables ou des méthodes de nos objets). Dans mon précédent post j&#8217;évoquais &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Il arrive que l&#8217;on ai besoin d&#8217;utiliser un script javascript spécifique dans une vue. Un script dynamique qui nécessite d&#8217;être renseigné par des informations de php (utiliser des variables ou des méthodes de nos objets).</p>
<p>Dans mon précédent post j&#8217;évoquais les différentes possibilités d&#8217;inclure le javascript dans les vues.</p>
<ul>
<li>Mettre des balises &lt;script&gt; directement au milieu du html (un peu crade mais efficace)</li>
<li>Faire un fichier .js &laquo;&nbsp;en dur&nbsp;&raquo; dans le dossier /web/js (mais là on perd la possibilité d&#8217;utiliser du php)</li>
<li>Utiliser un slot dans le &lt;head&gt; du template</li>
<li>Utiliser une vue</li>
</ul>
<p>C&#8217;est ce dernier point que je vous propose de voir aujourd&#8217;hui.</p>
<p><span id="more-746"></span></p>
<p>Pour se dessiner un petit background on va prendre l&#8217;exemple d&#8217;une vue index dans un module d&#8217;actualités.<br />
Dans cette vue on veut faire un appel ajax sur un lien et on veut utiliser le routing pour définir l&#8217;url du script à appeler.</p>
<p>On va donc utiliser une action et deux vues, une pour la page html et une pour le javascript qui sera inclus dans la vue html. On utilise des sf_format différents.
<p>On créé la route qui servira pour les deux vues (/app/frontend/config/routing.yml).</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('p746code36'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74636"><td class="code" id="p746code36"><pre class="yml" style="font-family:monospace;">...
actu_index:
  url:   /actualites/index.:sf_format
  param: { module: actu, action: index, sf_format: html }
...</pre></td></tr></table></div>

<p>Dans notre action on récupère juste les dernières actualités à afficher dans la page html (/app/frontend/modules/actu/actions/actions.class.php).</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('p746code37'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74637"><td class="code" id="p746code37"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> actuActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">actus</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Actu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLast</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La vue Html. C&#8217;est la que ca se passe ! On fais un use_javascript() auquel on passe le url_for() de la même vue en spécifiant juste le sf_format à &#8216;js&#8217; (/app/frontend/modules/actu/templates/indexSuccess.php).</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('p746code38'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74638"><td class="code" id="p746code38"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span>url_for<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@actu_index?sf_format=js'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;liste_actus&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;">$actus</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$actu</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>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;actu&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>h3<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;">$actu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTitre</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>h3<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<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;">$actu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTexteCourt</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>p<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;action&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Lire la suite'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'@actu_detail'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<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>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Et donc la vue js sera inclue par la vue html qui rajoute dans le head l&#8217;appel au fichier.</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('p746code39'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74639"><td class="code" id="p746code39"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;/actualites/index.js&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Il ne reste plus qu&#8217;a faire la script javascript dans la vue /app/frontend/modules/actu/templates/indexSuccess.js.php ou on peut avoir accès  à tous les éléments de symfony que l&#8217;on désire.</p>
<p>Par exemple là un peut appel ajax en jQuery ou je récupère l&#8217;url du script appelé grâce au routing.</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('p746code40'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74640"><td class="code" id="p746code40"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.action a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>
      <span style="color: #3366CC;">'&lt;?php echo url_for('</span><span style="color: #339933;">@</span>actu_detail<span style="color: #3366CC;">') ?&gt;'</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #3366CC;">'script'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Il se peut que dans la vue javascript on n&#8217;ait pas besoin d&#8217;exécuter toute l&#8217;action.<br />
Par exemple ici, dans ma vue javascript, je n&#8217;ai pas besoin des dernières actualités, il est donc possible de filtrer pour alléger l&#8217;action grâce au sf_format.</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('p746code41'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74641"><td class="code" id="p746code41"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> actuActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_format'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'js'</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;">actus</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Actu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLast</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>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Après, libre a chacun de voir si on doit utiliser la même action que la vue html ou si la vue javascript nécessite sa propre action.</p>
<p>En utilisant une action séparée pour la vue javascript on peut s&#8217;amuser à pousser le vice du camouflage en utilisant un routing qui fasse croire que l&#8217;on appelle un fichier .js (Attention si jamais un fichier avec le même nom existe réellement dans le répertoire /web/js c&#8217;est ce dernier qui sera inclus).</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('p746code42'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74642"><td class="code" id="p746code42"><pre class="yml" style="font-family:monospace;">...
actu_index_js:
  url:   /js/actu.:sf_format
  param: { module: actu, action: index, sf_format: js }
...</pre></td></tr></table></div>

<p><b>Avantage de cette technique :</b></p>
<ul>
<li>Un code source html super &laquo;&nbsp;clean&nbsp;&raquo;</li>
</ul>
<p><b>Inconvéniant :</b></p>
<ul>
<li>Pour une page html, on fait deux appels à symfony.<br />
A utiliser avec parcimonie et bien optimiser les actions pour ne pas faire des requêtes inutiles sur la base de donnée.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Listes déroulantes mises à jours en Ajax avec jQuery</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/listes-deroulantes-mises-a-jours-en-ajax-avec-jquery-704</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/listes-deroulantes-mises-a-jours-en-ajax-avec-jquery-704#comments</comments>
		<pubDate>Wed, 17 Jun 2009 07:49:39 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Liste déroulante]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=704</guid>
		<description><![CDATA[Un petit TIPS pour faire des listes déroulantes liées qui s&#8217;enrichissent en fonction de la valeur choisie sur l&#8217;une d&#8217;entre elles. (J&#8217;ai l&#8217;impression que la phrase est très compliqué pour pas grand chose ^^) Le tout en Ajax en utilisant &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/listes-deroulantes-mises-a-jours-en-ajax-avec-jquery-704">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Un petit TIPS pour faire des listes déroulantes liées qui s&#8217;enrichissent en fonction de la valeur choisie sur l&#8217;une d&#8217;entre elles.<br />
(J&#8217;ai l&#8217;impression que la phrase est très compliqué pour pas grand chose ^^)<br />
Le tout en Ajax en utilisant jQuery.<br />
<span id="more-704"></span><br />
Dans mon exemple, ça sera tout simplement un formulaire Lambda avec des listes déroulante pour les Régions et les Départements.<br />
Le fonctionnement est le suivant. Par défaut les listes déroulantes sont initialisées avec toutes les valeurs. Dés que l&#8217;on choisi une valeur pour la région, la liste déroulante des département affine sa liste pour ne proposer que les départements de la région saisie.</p>
<p>Vite fait, le schéma utilisé :</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('p704code48'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70448"><td class="code" id="p704code48"><pre class="yml" style="font-family:monospace;">...
Region:
  tableName:  region
  actAs:
    Sluggable:
      unique: true
      fields: [nom]
  columns:
    id:       { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    nom:      { type: string(255), notnull: true }
&nbsp;
Departement:
  tableName: departement
  actAs:
    Sluggable:
      unique: true
      fields: [nom]
  columns:
    id:        { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    nom:       { type: string(255), notnull: true }
    region_id: { type: integer(4), unsigned: true }
  relations:
    Region:
      local:        region_id
      foreign:      id
      foreignAlias: Departements
      onDelete:     CASCADE
...</pre></td></tr></table></div>

<p>Juste pour mettre en évidence la relation entre le Département et la Région, avec le très important le foreignAlias que j&#8217;aime tant <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Pour faire fonctionner tout ça on va avoir besoin de :<br />
 &#8211; 1 route<br />
 &#8211; 1 action minuscule<br />
 &#8211; 1 partial de 4 lignes<br />
 &#8211; 1 tout petit bout de javascript</p>
<p>La route :</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('p704code49'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70449"><td class="code" id="p704code49"><pre class="javascript" style="font-family:monospace;"># routing.<span style="color: #660066;">yml</span>
...
<span style="color: #660066;">ajax_departement</span><span style="color: #339933;">:</span>
  url<span style="color: #339933;">:</span>   <span style="color: #339933;">/</span>ajax<span style="color: #339933;">/</span>departement
  param<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> module<span style="color: #339933;">:</span> lambda<span style="color: #339933;">,</span> action<span style="color: #339933;">:</span> ajaxDepartement <span style="color: #009900;">&#125;</span>
...</pre></td></tr></table></div>

<p>L&#8217;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('p704code50'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70450"><td class="code" id="p704code50"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// actions.class.php</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * requete ajax pour avoir la liste des déparements de la région
   *
   * @param sfWebRequest $request
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeAjaxDepartement<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$region</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Region'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneById</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'region'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lambda/selectDepartement'</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;">'region'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$region</span><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>Le partial :</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('p704code51'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70451"><td class="code" id="p704code51"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// _selectDepartement.php</span>
<span style="color: #339933;">&lt;</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>option<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;">$region</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDepartements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$departement</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>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$departement-&gt;getId</span>() ?&gt;&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;">$departement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNom</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>option<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></pre></td></tr></table></div>

<p>Et enfin le petit bout de code jQuery à rajouter au formulaire :</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('p704code52'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p70452"><td class="code" id="p704code52"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mon_formulaire_lambda_region_id&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/ajax/departement&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> region<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mon_formulaire_lambda_departement_id&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Pour le javascript plusieurs solutions. Soit l&#8217;inclure directement dans la vue avec les balises <script></script> comme je l&#8217;ai fait ici.<br />
Soit faire un fichier .js que l&#8217;on met dans /web/js/mon_fichier.js (bien mais pas top <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ).</p>
<p>Le plus &laquo;&nbsp;propre&nbsp;&raquo; est de faire une vue et d&#8217;utiliser le sf_format et d&#8217;inclure le fichier via une route.<br />
On verra ça lors d&#8217;un prochain post <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>@bientôt !</p>
<p>NB : Bien entendu il faut que jQuery soi inclus :<br />
 &#8211; Soit il est inclus dans le view.yml<br />
 &#8211; Soit directement dans la vue avec un use_javascript(&#8216;jQuery.js&#8217;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/listes-deroulantes-mises-a-jours-en-ajax-avec-jquery-704/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Lexik @ Symfony Live</title>
		<link>http://www.lexik.fr/blog/symfony/non-classe/lexik-symfony-live-681</link>
		<comments>http://www.lexik.fr/blog/symfony/non-classe/lexik-symfony-live-681#comments</comments>
		<pubDate>Wed, 03 Jun 2009 09:04:02 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Non classé]]></category>
		<category><![CDATA[lexik]]></category>
		<category><![CDATA[live]]></category>
		<category><![CDATA[paris]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=681</guid>
		<description><![CDATA[Lexik sera présent le 11 et 12 Juin prochain à la conférence Symfony Live à Paris. Un programme qui semble très intéressant est ici : http://www.symfony-live.com/schedule Si vous souhaitez participer aussi ne tardez plus à vous inscrire :  http://www.symfony-live.com/ Vous &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/non-classe/lexik-symfony-live-681">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Lexik sera présent le 11 et 12 Juin prochain à la conférence Symfony Live à Paris.</p>
<p>Un programme qui semble très intéressant est ici : <a href="http://www.symfony-live.com/schedule">http://www.symfony-live.com/schedule</a></p>
<p>Si vous souhaitez participer aussi ne tardez plus à vous inscrire :  <a href="http://www.symfony-live.com/">http://www.symfony-live.com/</a></p>
<p style="text-align: center;"><img class="size-full wp-image-684 alignnone" title="yoann" src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2009/06/yoann.jpg" alt="yoann" width="110" height="137" /><br />
Vous pourrez retrouver Yoann la bas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/non-classe/lexik-symfony-live-681/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Utilisation de sfDoctrineGuardPlugin pour la gestion des utilisateurs</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/utilisation-de-sfdoctrineguardplugin-pour-la-gestion-des-utilisateurs-634</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/utilisation-de-sfdoctrineguardplugin-pour-la-gestion-des-utilisateurs-634#comments</comments>
		<pubDate>Wed, 27 May 2009 11:01:50 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sfguard]]></category>
		<category><![CDATA[utilisateur]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=634</guid>
		<description><![CDATA[sfDoctrineGuardPlugin comme son nom l&#8217;indique est la version Doctrine de sfGuardPlugin qui est THE plugin de gestion des utilisateurs de Symfony. Il comporte des formulaires d&#8217;identification et d&#8217;inscription très basique, mais son principal point fort est la gestion des droits &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/utilisation-de-sfdoctrineguardplugin-pour-la-gestion-des-utilisateurs-634">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>sfDoctrineGuardPlugin comme son nom l&#8217;indique est la version Doctrine de sfGuardPlugin qui est <strong>THE plugin</strong> de gestion des utilisateurs de Symfony.</p>
<p>Il comporte des formulaires d&#8217;identification et d&#8217;inscription très basique, mais son principal point fort est la gestion des droits associés aux utilisateurs, la possibilité de gérer des groupes le tout générant automatiquement les crédentials qui va permettre de sécuriser l&#8217;application de manière très simple.</p>
<p><span id="more-634"></span></p>
<p>Je ne reviendrai pas sur la gestion des crédentials qui est très bien expliquée dans le <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/13#chapter_13_application_security" target="_blank">Jobeet #13</a>.</p>
<p>De même pour l&#8217;installation. <a href="http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin" targer="_blank">Le readme</a> est très bien fait et explique très clairement comment faire.</p>
<h2>Le modèle de données</h2>
<p>Le modèle de données du plugin comporte la table des Utilisateurs, des Groupes et des Permissions ainsi que les tables d&#8217;associations entre Utilisateurs/Permissions, Groupes/Permissions et Utilsateurs/Groupes.</p>
<p>Ce sont les permissions attribuées à un utilisateur (directement ou par ses groupes) qui déterminent les crédentials qu&#8217;il aura une fois logué (C&#8217;est le nom de la permission qui sera le nom du crédential).</p>
<p>Pour illustrer tout ca, on va voir un petit exemple.</p>
<p>On prends une structure simple, avec 2 groupes et 3 permissions.<br />
Les permissions de Lecture, Ecriture et Téléchargement (même si la loi Hadopie a été votée ^^).<br />
Les groupes Admin qui a tous les droits et Membre qui n&#8217;a que le droit de lecture.</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('p634code61'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63461"><td class="code" id="p634code61"><pre class="yml" style="font-family:monospace;">&nbsp;
sfGuardPermission:
  pLecture:
    name: lecture
  pEcriture:
    name: ecriture
  pTelegargement:
    name: telechargement
&nbsp;
sfGuardGroup:
  gAdmin:
    name: admin
  gMembre:
    name: membre
&nbsp;
sfGuardGroupPermission:
  gp1:
    sfGuardGroup:      gAdmin
    sfGuardPermission: pLecture
  gp2:
    sfGuardGroup:      gAdmin
    sfGuardPermission: pEcriture
  gp3:
    sfGuardGroup:      gAdmin
    sfGuardPermission: pTelegargement
  gp4:
    sfGuardGroup:      gMembre
    sfGuardPermission: pLecture</pre></td></tr></table></div>

<p>Et 3 utilisateurs : Toto, Titi et Tata à qui on va définir des droits différents.</p>
<p>- Toto sera dans le groupe admin, il aura ainsi tout les droits.<br />
- Titi et Tata seront dans le groupe Membre et auront ainsi seulement le droit de Lecture.<br />
- Titi a en plus le droit de téléchargement.</p>
<p>Ce qui se traduit en fixture 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('p634code62'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63462"><td class="code" id="p634code62"><pre class="yml" style="font-family:monospace;">&nbsp;
sfGuardUser:
  Toto:
    username: toto
    password: t0t0
  Titi:
    username: titi
    password: t1t1
  Tata:
    username: tata
    password: t4t4
&nbsp;
sfGuardUserGroup:
  ug1:
    sfGuardUser:  Toto
    sfGuardGroup: gAdmin
  ug2:
    sfGuardUser:  Titi
    sfGuardGroup: gMembre
  ug3:
    sfGuardUser:  Tata
    sfGuardGroup: gMembre
&nbsp;
sfGuardUserPermission:
  up1:
    sfGuardUser:       Titi
    sfGuardPermission: pTelegargement</pre></td></tr></table></div>

<p>Dans un module lambda, on peut donc très facilement sécuriser nos pages comme suit.</p>
<p>/module/config/security.yml</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('p634code63'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63463"><td class="code" id="p634code63"><pre class="yml" style="font-family:monospace;">secure:
  is_secure:   on
&nbsp;
telechargement:
  is_secure:   on
  credentials: [lecture, telechargement]
&nbsp;
default:
  is_secure:   off</pre></td></tr></table></div>

<p>La page secure nécessite que l&#8217;utilisateur soit connecté mais il n&#8217;y a aucune restriction de crédential. Les 3 utilisateur, une fois logés, pourront y accéder.</p>
<p>La page téléchargement nécessite 2 permissions lecture et téléchargement. Seuls Toto et Titi y auront accès. Tata sera redirigé automatiquement vers la page d&#8217;erreur de permissions.</p>
<h2>La redirection après l&#8217;authentification.</h2>
<p>L&#8217;authentification est gérée par le plugin, il suffit d&#8217;envoyer l&#8217;utilisateur vers la route @sf_guard_signin.</p>
<p>Une fois l&#8217;authentification effectuée, le script redirige l&#8217;utilisateur. Par défaut l&#8217;utilisateur est redirigé vers le HTTP_REFERER.</p>
<p>Heureusement on peut aussi déterminer une route vers laquelle on veut être redirigé après l&#8217;authentification de plusieurs manières.</p>
<p>Premièrement via des variable du app.yml</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('p634code64'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63464"><td class="code" id="p634code64"><pre class="yml" style="font-family:monospace;">all:
  sf_guard_plugin:
    success_signin_url:      @my_route?param=value
    success_signout_url:     module/action</pre></td></tr></table></div>

<p>Autre méthode qui consiste à utiliser le comportement par défaut de redirection vers le referer, mais en utilisant la méthode setReferer() de la classe sfGuardSecurityUser.</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('p634code65'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63465"><td class="code" id="p634code65"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> moduleActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #339933;">...</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeAction<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">...</span>
    <span style="color: #000088;">$this</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;">setReferer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@my_route'</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;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@sf_guard_signin'</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>

<p>L&#8217;ordre de priorité est :<br />
- la variable du fichier app.yml<br />
- le getReferer() du GuardUser<br />
- le HTTP_REFERER</p>
<h2>Connecter automatiquement un utilisateur</h2>
<p>Il est possible de connecter automatiquement un utilisateur grâce à la méthode signin() à la quelle on doit passer une instance de sfGuardUser.</p>
<p>Par exemple dans une action quelconque :</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('p634code66'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63466"><td class="code" id="p634code66"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> moduleActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #339933;">...</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeAction<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">...</span>
    <span style="color: #000088;">$utilisateur</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sfGuardUser'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneByUsername</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'toto'</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">signin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$utilisateur</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">...</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Associer un ou plusieurs groupes à un utilisateur</h2>
<p>On a vu au début de l&#8217;article comment associer des groupes aux utilisateurs par le fixture.</p>
<p>On va voir ici comment le faire en php.</p>
<p>Par exemple si on avait à le faire dans le script d&#8217;inscription et qu&#8217;on veulait associer automatiquement le groupe membre aux utilisateurs qui s&#8217;inscrivent.</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('p634code67'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63467"><td class="code" id="p634code67"><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> executeInscription<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfGuardUserFormRegister<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// la classe de formulaire sfGuardUserFormRegister n'existe pas dans le plugin par defaut</span>
  <span style="color: #666666; font-style: italic;">// je la mets en annexe à la fin de l'article</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><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: #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;">form</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: #000088;">$permission</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sfGuardGroup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneByName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'membre'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$utilisateur</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$utilisateur</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'permissions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$permission</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$this</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;">signIn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$utilisateur</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;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@homepage'</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>

<h2>Annexe</h2>

<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('p634code68'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p63468"><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
</pre></td><td class="code" id="p634code68"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * formulaire d'inscription
 *
 * @package    form
 * @subpackage sfGuardUser
 * @author     Lexik
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> sfGuardUserFormRegister <span style="color: #000000; font-weight: bold;">extends</span> PluginsfGuardUserForm
<span style="color: #009900;">&#123;</span>
&nbsp;
  <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>
    <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'groups_list'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'permissions_list'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'algorithm'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'salt'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_active'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_super_admin'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'last_login'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'created_at'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'updated_at'</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span>     <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputPassword<span style="color: #009900;">&#40;</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password_bis'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputPassword<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <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;">'username'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Email* :'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'password'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Mot de passe* :'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'password_bis'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Confirmation* :'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span>     <span style="color: #339933;">=</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: #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;">'invalid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Cet email n\'est pas valide.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Champ obligatoire.'</span><span style="color: #009900;">&#41;</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;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span>     <span style="color: #339933;">=</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;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'min_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6</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_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&quot;%value%&quot; est trop court (%min_length% lettres minimum).'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Champ obligatoire.'</span><span style="color: #009900;">&#41;</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;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password_bis'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</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;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'min_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">6</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_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&quot;%value%&quot; est trop court (%min_length% lettres minimum).'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Champ obligatoire.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mergePostValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> sfValidatorSchemaCompare<span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span>
      sfValidatorSchemaCompare<span style="color: #339933;">::</span><span style="color: #004000;">EQUAL</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'password_bis'</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>
      <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Les champs doivent être identiques.'</span><span style="color: #009900;">&#41;</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: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/utilisation-de-sfdoctrineguardplugin-pour-la-gestion-des-utilisateurs-634/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Stage chez Lexik été 2009</title>
		<link>http://www.lexik.fr/blog/symfony/non-classe/stage-chez-lexik-ete-2009-629</link>
		<comments>http://www.lexik.fr/blog/symfony/non-classe/stage-chez-lexik-ete-2009-629#comments</comments>
		<pubDate>Mon, 04 May 2009 09:10:25 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Non classé]]></category>
		<category><![CDATA[stage]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=629</guid>
		<description><![CDATA[Lexik propose 2 stages à Montpellier pour cet été 2009 : Stage Développeur PHP : Compétence : Connaissance de PHP5, POO Profil : Rigoureux, curieux. Mission : Vous integrez notre équipe de développement sur la réalisation de projet Interne : &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/non-classe/stage-chez-lexik-ete-2009-629">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Lexik propose 2 stages à Montpellier pour cet été 2009 :</p>
<p><strong>Stage Développeur PHP :</strong></p>
<p>Compétence : Connaissance de PHP5, POO<br />
  Profil : Rigoureux, curieux.<br />
Mission : Vous integrez notre équipe de développement sur la réalisation de projet Interne : Intranet/Site Internet.<br />
Développement avec le Framework Symfony</p>
<p><strong>Stage Marketing et gestion site Internet</strong></p>
<p>Compétence : Connaissance d&#8217;Internet, bureautique<br />
Profil : Appliqué, bonne rédaction<br />
Mission : Vous travaillerez sur la visibilité des projets mis en ligne ainsi que sur les actions marketing et le référencement.</p>
<p align="center">Envoyez CV : contact@lexik.fr</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/non-classe/stage-chez-lexik-ete-2009-629/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Schema.yml Doctrine, Bonnes pratiques, Convention de nommage et fonctions magiques</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/schemayml-doctrine-bonnes-pratiques-convention-de-nommage-et-fonctions-magiques-508</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/schemayml-doctrine-bonnes-pratiques-convention-de-nommage-et-fonctions-magiques-508#comments</comments>
		<pubDate>Tue, 21 Apr 2009 12:14:33 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=508</guid>
		<description><![CDATA[On c'est rendu compte ici qu'il y avait pas mal de questions en rapport avec le schema.yml qui ressortaient régulièrement.

Le schema.yml est généralement trop vite oublié. C'est facile à faire, ça génère la base sans trop se poser de questions, et puis on l'oublie... Alors que le schema.yml est certainement le fichier le plus important d'une application Symfony.

Je vais donc essayer de regrouper dans ce post les questions auxquelles on réponds généralement par "Regardes dans ton schema.yml" où "Comment est ce que tu l'as défini dans ton schema.yml ?". Notamment au niveau des définitions des relations et les méthodes magiques qui en découlent.<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/schemayml-doctrine-bonnes-pratiques-convention-de-nommage-et-fonctions-magiques-508">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>On s&#8217;est rendu compte ici qu&#8217;il y avait pas mal de questions en rapport avec le schema.yml qui ressortaient régulièrement.</p>
<p>Le schema.yml est généralement trop vite oublié. C&#8217;est facile à faire, ça génère la base sans trop se poser de questions, et puis on l&#8217;oublie&#8230; Alors que le schema.yml est certainement <strong>le fichier le plus important</strong> d&#8217;une application Symfony.  </p>
<p>Je vais donc essayer de regrouper dans ce post les questions auxquelles on répond généralement par &laquo;&nbsp;Regardes dans ton schema.yml&nbsp;&raquo; où &laquo;&nbsp;Comment est ce que tu l&#8217;as défini dans ton schema.yml ?&nbsp;&raquo;. </p>
<p>Notamment au niveau des définitions des relations et les méthodes magiques qui en découlent.</p>
<p><span id="more-508"></span></p>
<p>Tout d&#8217;abord un petit bookmark des pages à lire et à relire de la documentation doctrine. </p>
<ul>
<li><a href="http://www.doctrine-project.org/documentation/manual/1_1/en/defining-models#columns">Les types de colonnes</a></li>
<li><a href="http://www.doctrine-project.org/documentation/manual/1_1/en/defining-models#relationships">Les relations</a></li>
<li><a href="http://www.doctrine-project.org/documentation/manual/1_1/en/data-validation#introduction">Les data validations</a></li>
<li><a href="http://www.doctrine-project.org/documentation/manual/1_1/en/behaviors#introduction">Les behaviors</a></li>
</ul>
<p>(Personnellement je trouve que la documentation Doctrine est très bien faite. Les exemples omniprésent et la rendent très explicite, même pour un anglophobe.)</p>
<p>
Pour ce post j&#8217;ai fait le schema.yml d&#8217;une application lambda. On a des utilisateurs, des groupes, la relation n:n entre les deux. Et pour rajouter une petite relation 1:n les utilisateurs ont des photos. (original non?)</p>
<p>
J&#8217;ai utilisé des behaviors Timestampable et Sluggable.<br />
Dans les types j&#8217;en ai profité pour tester le Enum que je n&#8217;utilisais pas jusqu&#8217;à présent, mais je pense que dans un avenir proche je vais m&#8217;en servir beaucoup plus <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  <br />
Pareil dans les data validation le &laquo;&nbsp;email: true&nbsp;&raquo; sur le champ email et le &laquo;&nbsp;past: true&nbsp;&raquo; sur la date de naissance sont assez énormes et permettent d&#8217;avoir déjà les validators adéquats dans les classes formulaires.</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="left2">Download <a href="http://www.lexik.fr/blog/symfony/wp-content/plugins/wp-codebox/wp-codebox.php?p=508&amp;download=schema.yml">schema.yml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50869"><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
</pre></td><td class="code" id="p508code69"><pre class="yml" style="font-family:monospace;">Utilisateur:
  tableName:        test_utilisateur
  actAs:
    Timestampable:  ~
    Sluggable:
      unique:       true
      fields:       [nom,prenom]
      canUpdate:    true
  columns:
    id:             { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    sexe:           { type: enum, values: ['','Homme','Femme'], default: 'Homme' }
    nom:            { type: string(255) }
    prenom:         { type: string(255) }
    date_naissance: { type: date, past: true }
    email:          { type: string(255), notnull: true, unique: true, email: true }
  relations:
    Groupes:
      class:        Groupe
      refClass:     Membre
      local:        utilisateur_id
      foreign:      groupe_id
&nbsp;
&nbsp;
Photo:
  tableName:        test_photo
  actAs:
    Timestampable:  ~
  columns:
    id:             { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    fichier:        { type: string(255), notnull: true }
    utilisateur_id: { type: integer(4), unsigned: true, primary: true }
  relations:
    Utilisateur:
      local:        utilisateur_id
      foreign:      id
      foreignAlias: Photos
      onDelete:     CASCADE
&nbsp;
&nbsp;
Membre:
  tableName:        test_membre
  columns:
    utilisateur_id: { type: integer(4), unsigned: true, primary: true }
    groupe_id:      { type: integer(4), unsigned: true, primary: true }
  relations:
    Utilisateur:
      local:        utilisateur_id
      foreign:      id
      foreignAlias: Membres
      onDelete:     CASCADE
    Groupe:
      local:        groupe_id
      foreign:      id
      foreignAlias: Membres
      onDelete:     CASCADE
&nbsp;
&nbsp;
Groupe:
  tableName:        test_groupe
  columns:
    id:             { type: integer(4), unsigned: true, primary: true, autoincrement: true }
    nom:            { type: string(255), notnull: true }
  relations:
    Utilisateurs:
&nbsp;
      class:        Utilisateur
      refClass:     Membre
      local:        groupe_id
      foreign:      utilisateur_id</pre></td></tr></table></div>

<h2>La convention de nommage</h2>
<p><b>Le nom des objets :</b> Le plus court et le plus explicite possible. En CamelCase avec la première lettre en majuscule et au singulier. Pourquoi la 1er lettre en majuscule. Si la table a le même nom, ça permet de les dissocier facilement pour éviter les ambiguïté, notamment dans la construction des requête en DQL.</p>
<p><b>Le nom des relations :</b> Si possible, je donne le même nom que l&#8217;objet cible. Au singulier si on est sur une relation N:1 ou 1:1 et au pluriel quand on est sur une relation 1:N ou N:N (généralement les foreignAlias). La aussi la 1er lettre en majuscule est importante, car elle permet de conserver une syntaxe camelCase sur les accessers magiques.</p>
<p>  Par exemple sur l&#8217;objet Photo : </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('p508code70'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50870"><td class="code" id="p508code70"><pre class="yml" style="font-family:monospace;">Photo:
  ...
  relations:
    Utilisateur:
      local:        utilisateur_id
      foreign:      id</pre></td></tr></table></div>

<p>L&#8217;accesseur magique sera :</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('p508code71'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50871"><td class="code" id="p508code71"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ma_photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUtilisateur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Alors que si on appelle la relation en minuscule :</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('p508code72'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50872"><td class="code" id="p508code72"><pre class="yml" style="font-family:monospace;">Photo:
  ...
  relations:
    utilisateur:
      local:        utilisateur_id
      foreign:      id</pre></td></tr></table></div>

<p>L&#8217;accesseur magique sera</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('p508code73'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50873"><td class="code" id="p508code73"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ma_photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getutilisateur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Et du coup on perd la syntaxe camelCase qui est généralisée dans tout le framework.<br />
C&#8217;est du chipotage mais ca peut être source d&#8217;erreur bête qui fait perdre du temps.</p>
<h2>Les TOC (Troubles Obsessionnels de Codage :p) ou Bonnes pratiques</h2>
<p>Sur les relations 1:N et 1:1, je définie toute la relation dans l&#8217;objet qui possède la clé étrangère. Pour essayer de ne pas alourdir trop mon schema.yml et aussi par faignantise.</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('p508code74'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50874"><td class="code" id="p508code74"><pre class="yml" style="font-family:monospace;">Photo:
  ...
  relations:
    Utilisateur:
      local:        utilisateur_id
      foreign:      id
      foreignAlias: Photos
      onDelete:     CASCADE</pre></td></tr></table></div>

<p>Cette relation défini 2 méthodes magiques Photo::getUtilisateur() qui va retourner l&#8217;objet Utilisateur lié à la photo et Utilisateur::getPhotos() qui retourne une collection d&#8217;objets Photo liés à utilisateur.</p>
<p>Cette même relation peut se décrire aussi en la décomposant en 2 parties.</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('p508code75'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50875"><td class="code" id="p508code75"><pre class="yml" style="font-family:monospace;">Utilisateur:
  ...
  relations:
    Photos:
      local:        id
      foreign:      utilisateur_id
      onDelete:     CASCADE
&nbsp;
Photo:
  ...
  relations:
    Utilisateur:
      local:        utilisateur_id
      foreign:      id
      onDelete:     CASCADE</pre></td></tr></table></div>

<p>Les 2 méthodes marchent parfaitement et ont leurs avantages et leurs inconvénients.</p>
<p>Sur les relations N:N, je définie toute la relation dans la Classe de liaison, et sur les objets externes seulement la partie qui les concernent. Pour éviter les multiples redéfinitions.</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('p508code76'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50876"><td class="code" id="p508code76"><pre class="yml" style="font-family:monospace;">Membre:
  ...
  relations:
    Utilisateur:
      local:        utilisateur_id
      foreign:      id
      foreignAlias: Membres
      onDelete:     CASCADE
    Groupe:
      local:        groupe_id
      foreign:      id
      foreignAlias: Membres
      onDelete:     CASCADE
&nbsp;
&nbsp;
Utilisateur:
  ...
  relations:
    Groupes:
      class:        Groupe
      refClass:     Membre
      local:        utilisateur_id
      foreign:      groupe_id
&nbsp;
&nbsp;
Groupe:
  ...
  relations:
    Utilisateurs:
      class:        Utilisateur
      refClass:     Membre
      local:        groupe_id
      foreign:      utilisateur_id</pre></td></tr></table></div>

<p>Sur les objets, j&#8217;aime bien avoir des noms simples et explicites mais paradoxalement, j&#8217;aime bien préfixer mes tables dans la base de donnée. C&#8217;est pourquoi je redéfinie systématiquement le tableName des objets dans le schema.yml</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('p508code77'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50877"><td class="code" id="p508code77"><pre class="yml" style="font-family:monospace;">Utilisateur:
  tableName:        test_utilisateur
  ...</pre></td></tr></table></div>

<p>Sur les objets l&#8217;id est généré automatiquement mais il est de type bigint(20) signé. Et là aussi, comme je suis un gros maniaque et que je n&#8217;aime pas avoir des id signé qui plus est en bigint. Je redéfini l&#8217;id en int signé.</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('p508code78'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50878"><td class="code" id="p508code78"><pre class="yml" style="font-family:monospace;">Utilisateur:
  ...
  columns:
    id:             { type: integer(4), unsigned: true, primary: true, autoincrement: true }</pre></td></tr></table></div>

<p>Attention, il est possible de définir les relations à plusieurs endroits et de plusieurs manières différentes. Il faut essayer de se tenir à une méthodologie la plus stricte possible pour éviter des redéfinitions de relations.<br />
Si il y a des redéfinitions, Symfony ne va pas forcement les détecter lors de la re-génération des classes et ça risque de ne pas fonctionner correctement.</p>
<h2>Créer des relations avec les objets d&#8217;un plugin</h2>
<p>On va prendre le cas de sfGuard qui est un des plugins les plus utilisés.</p>
<p>Petite chose à savoir. Quand on utilise sfGuard, l&#8217;id de l&#8217;objet sfGuardUser est un int signé. Si vous avez besoin de faire des jointures pensez bien à utiliser un integer(4).</p>
<p>(Le type des clé étrangère est très important et source de pas mal de problèmes.)</p>
<p>Si on voulait lier l&#8217;objet Photo à sfGuardUser il faudrait écrire quelque-chose comme :</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('p508code79'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50879"><td class="code" id="p508code79"><pre class="yml" style="font-family:monospace;">Photo:
  ...
  columns:
    ...
    user_id: { type: integer(4) }
  relations:
    User:
      class:            sfGuardUser
      local:            user_id
      foreign:          id
      foreignAlias:     Photos
      onDelete:         CASCADE</pre></td></tr></table></div>

<p>Toujours dans l&#8217;hypothèse de l&#8217;intégration de sfGuard à la place de mon objet Utilisateur.<br />
Pour les relations N:N, étant donné que l&#8217;on a pas accès au schema.yml de l&#8217;objet sfGuarduser avec lequel on va se lier. Il faut définir toutes les relations de manière externe.</p>
<p>Pour la relation avec les groupes ça donnerais :</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('p508code80'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50880"><td class="code" id="p508code80"><pre class="yml" style="font-family:monospace;">Membre:
  ...
  relations:
    Utilisateur:
      class:        sfGuardUser
      local:        utilisateur_id
      foreign:      id
      foreignAlias: Membres
      onDelete:     CASCADE
    Groupe:
      local:        groupe_id
      foreign:      id
      foreignAlias: Membres
      onDelete:     CASCADE
&nbsp;
&nbsp;
Groupe:
  ...
  relations:
    Utilisateurs:
      class:        sfGuardUser
      refClass:     Membre
      local:        groupe_id
      foreign:      utilisateur_id
      foreignAlias: Groupes</pre></td></tr></table></div>

<h2>Méthodes magiques dans les objets</h2>
<p>On a vu que les nom des relations et les foreignAlias engendraient des méthodes magiques qui permettent de remonter facilement les objets de la relation.<br />
Si on reprends le schema.yml du début, la liste des méthodes magiques est la suivante :</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('p508code81'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50881"><td class="code" id="p508code81"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">//methodes magiques su l'objet Utilisateur</span>
<span style="color: #000088;">$utilisateur</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Utilisateur<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGroupes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMembres</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;">//methodes magiques su l'objet Photo</span>
<span style="color: #000088;">$photo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Photo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUtilisateur</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;">//methodes magiques su l'objet Membre</span>
<span style="color: #000088;">$membre</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Membre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$membre</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUtilisateur</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$membre</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGroupe</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;">//methodes magiques su l'objet Groupe</span>
<span style="color: #000088;">$groupe</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Groupe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$groupe</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMembres</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$groupe</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUtilisateurs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Les getters et les setters sont aussi des méthodes magiques.</p>
<p>Il y a un petit piège à éviter si on veut surcharger un getter ou un setter.</p>
<p>Par exemple si on vaut surcharger le getter Nom de l&#8217;objet Utilisateur, on a tendance a vouloir écrire :</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('p508code82'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50882"><td class="code" id="p508code82"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UtilisateurTable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Table
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getNom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">getNom</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;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Et bien il ne faut pas ! Ça fait en fait une boucle infinie.<br />
Il faut écrire :</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('p508code83'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50883"><td class="code" id="p508code83"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> UtilisateurTable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Table
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getNom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span>_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Finders magiques dans les classes Table</h2>
<p>Comme pour les getters, il y a deux finders magiques par champ dans la classe Table.<br />
Un findBy<em>Lechamp</em> et un findOneBy<em>Lechamp</em>. Le premier qui retourne une collection d&#8217;objets (même s&#8217;il n&#8217;y en a qu&#8217;un) et le second qui renvoie un objet seul.</p>
<p>Par exemple:</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('p508code84'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50884"><td class="code" id="p508code84"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$utilisateur</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Utilisateur'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneByNom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Toto'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Le nombre de requêtes</h2>
<p>Le nombre de requêtes effectuer en base peut rapidement devenir impressionnant.</p>
<p>Mais si on y regarde de plus prés ce sont souvent de petites requêtes.<br />
On va voir comment jouer sur le nombre de requêtes générées avec un petit exemple.</p>
<p>Une action toute simple ou je récupère un objet Utilisateur par son slug.</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('p508code85'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50885"><td class="code" id="p508code85"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//actions.class.php</span>
<span style="color: #000000; font-weight: bold;">class</span> userActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">test_utilisateur</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Utilisateur'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findOneBySlug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'teta-toto'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Et la vue qui correspond</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('p508code86'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50886"><td class="code" id="p508code86"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//indexSuccess.php</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Utilisateur <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$test_utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPrenom</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>p<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Photos <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$test_utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGroupes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</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>p<span style="color: #339933;">&gt;</span>
&nbsp;
<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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test_utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPhotos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$photo</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: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$photo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFichier</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>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>
&nbsp;
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Groupes <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$test_utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGroupes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</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>p<span style="color: #339933;">&gt;</span>
&nbsp;
<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;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test_utilisateur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGroupes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$groupe</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: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$groupe</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNom</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>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></pre></td></tr></table></div>

<p>On vois que 3 requetes sont effectuées.</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('p508code87'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50887"><td class="code" id="p508code87"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">.</span> <span style="color: #993333; font-weight: bold;">SELECT</span> t<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span> t__id<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>sexe <span style="color: #993333; font-weight: bold;">AS</span> t__sexe<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>nom <span style="color: #993333; font-weight: bold;">AS</span> t__nom<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>prenom <span style="color: #993333; font-weight: bold;">AS</span> t__prenom<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>date_naissance <span style="color: #993333; font-weight: bold;">AS</span> t__date_naissance<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>email <span style="color: #993333; font-weight: bold;">AS</span> t__email<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>created_at <span style="color: #993333; font-weight: bold;">AS</span> t__created_at<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>updated_at <span style="color: #993333; font-weight: bold;">AS</span> t__updated_at<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>slug <span style="color: #993333; font-weight: bold;">AS</span> t__slug <span style="color: #993333; font-weight: bold;">FROM</span> test_utilisateur t <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>slug <span style="color: #66cc66;">=</span> ? <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>teta<span style="color: #66cc66;">-</span>toto <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">.</span> <span style="color: #993333; font-weight: bold;">SELECT</span> t<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span> t__id<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>nom <span style="color: #993333; font-weight: bold;">AS</span> t__nom<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">AS</span> t2__utilisateur_id<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>groupe_id <span style="color: #993333; font-weight: bold;">AS</span> t2__groupe_id <span style="color: #993333; font-weight: bold;">FROM</span> test_groupe t <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> test_membre t2 <span style="color: #993333; font-weight: bold;">ON</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> t2<span style="color: #66cc66;">.</span>groupe_id <span style="color: #993333; font-weight: bold;">WHERE</span> t2<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span>?<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">.</span> <span style="color: #993333; font-weight: bold;">SELECT</span> t<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span> t__id<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">AS</span> t__utilisateur_id<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>fichier <span style="color: #993333; font-weight: bold;">AS</span> t__fichier<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>created_at <span style="color: #993333; font-weight: bold;">AS</span> t__created_at<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>updated_at <span style="color: #993333; font-weight: bold;">AS</span> t__updated_at <span style="color: #993333; font-weight: bold;">FROM</span> test_photo t <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span>?<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>La 1er requête est effectuée lors du findOneBySlug() dans l&#8217;action.<br />
La seconde lors du getPhotos() dans la vue.<br />
Et la derniere lors du getGroupes() dans la vue également.</p>
<p>On peut obtimiser le nombre de requete en forceant les jointures.</p>
<p>Pour le même code si on surcharge le finder findOneBySlug() en y rajoutant toutes les jointures</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('p508code88'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50888"><td class="code" id="p508code88"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * /lib/model/doctrine/UtilisateurTable.class.php
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> UtilisateurTable <span style="color: #000000; font-weight: bold;">extends</span> Doctrine_Table
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> findOneBySlug<span style="color: #009900;">&#40;</span><span style="color: #000088;">$slug</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> Doctrine_Query<span style="color: #339933;">::</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Utilisateur u'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">leftJoin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'u.Photos'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">leftJoin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'u.Groupes'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'u.slug = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$slug</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchOne</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>On obtiens le même résultat avec une seule 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('p508code89'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p50889"><td class="code" id="p508code89"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span>  t<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span>  t__id<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>sexe <span style="color: #993333; font-weight: bold;">AS</span>  t__sexe<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>nom <span style="color: #993333; font-weight: bold;">AS</span>  t__nom<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>prenom <span style="color: #993333; font-weight: bold;">AS</span>  t__prenom<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>date_naissance <span style="color: #993333; font-weight: bold;">AS</span>  t__date_naissance<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>email <span style="color: #993333; font-weight: bold;">AS</span>  t__email<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>created_at <span style="color: #993333; font-weight: bold;">AS</span>  t__created_at<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>updated_at <span style="color: #993333; font-weight: bold;">AS</span>  t__updated_at<span style="color: #66cc66;">,</span> t<span style="color: #66cc66;">.</span>slug <span style="color: #993333; font-weight: bold;">AS</span>  t__slug<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span>  t2__id<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">AS</span>  t2__utilisateur_id<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>fichier <span style="color: #993333; font-weight: bold;">AS</span>  t2__fichier<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>created_at <span style="color: #993333; font-weight: bold;">AS</span>  t2__created_at<span style="color: #66cc66;">,</span> t2<span style="color: #66cc66;">.</span>updated_at <span style="color: #993333; font-weight: bold;">AS</span>  t2__updated_at<span style="color: #66cc66;">,</span> t3<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">AS</span>  t3__id<span style="color: #66cc66;">,</span> t3<span style="color: #66cc66;">.</span>nom <span style="color: #993333; font-weight: bold;">AS</span>  t3__nom <span style="color: #993333; font-weight: bold;">FROM</span> test_utilisateur t <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> test_photo t2 <span style="color: #993333; font-weight: bold;">ON</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> t2<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> test_membre t4 <span style="color: #993333; font-weight: bold;">ON</span> t<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> t4<span style="color: #66cc66;">.</span>utilisateur_id <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> test_groupe t3 <span style="color: #993333; font-weight: bold;">ON</span> t3<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> t4<span style="color: #66cc66;">.</span>groupe_id <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>slug <span style="color: #66cc66;">=</span> ? <span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>teta<span style="color: #66cc66;">-</span>toto <span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Il ne faut pas nonplus s&#8217;amuser a remonter la moitié de la base de donnée dans chaque requête, mais ça permet de mieu gérer la charge générée par les scripts.</p>
<h2>Supprimer ou renommer un objet</h2>
<p>Si on supprime ou qu&#8217;on renomme une classe, les classes générés ne sont pas nettoyées et il faut le faire &laquo;&nbsp;a la main&nbsp;&raquo; sinon, les objets sont toujours regénéré et les tables toujours présentes en base.</p>
<p>Par exemple si ou voulais supprimer l&#8217;objet Utilisateur parcequ&#8217;on a décidé de se servir de sfGuard pour gérer les utilisateurs.</p>
<p>Il faut supprimer :</p>
<ul>
<li>/lib/filter/doctrine/UtilisateurFormFilter.class</li>
<li>/lib/filter/doctrine/base/BaseUtilisateurFormFilter.class.php</li>
<li>/lib/form/doctrine/UtilisateurForm.class.php</li>
<li>/lib/form/doctrine/base/BaseUtilisateurForm.class.php</li>
<li>/lib/model/doctrine/Utilisateur.class.php</li>
<li>/lib/model/doctrine/UtilisateurTable.class.php</li>
<li>/lib/model/doctrine/base/Utilisateur.class.php</li>
</ul>
<p>Merci a ceux qui ont eu le courage d&#8217;aller jusqu&#8217;au bout. J&#8217;avoue que je ne pensais pas faire un post aussi long à la base.<br />
J&#8217;ai un peu tapé au kilomètre et je pense que je le remanierai d&#8217;ici quelques temps avec plus d&#8217;explications et beaucoup moins de fautes <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/schemayml-doctrine-bonnes-pratiques-convention-de-nommage-et-fonctions-magiques-508/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>JEditable et formulaire Symfony 1.2</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/jeditable-et-formulaire-symfony-12-502</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/jeditable-et-formulaire-symfony-12-502#comments</comments>
		<pubDate>Fri, 17 Apr 2009 07:57:17 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[JEditable]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=502</guid>
		<description><![CDATA[Comment intégrer un plugin jQuery dans un projet Symfony 1.2 ? La réponse à cette question ne pouvant pas tenir dans le modeste blog de Lexik.fr, je vais seulement vous expliquer comment intégrer la modification d&#8217;un champ &#171;&#160;INPUT&#160;&#187; en ajax &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/jeditable-et-formulaire-symfony-12-502">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Comment intégrer un plugin jQuery dans un projet Symfony 1.2 ?</p>
<p>La réponse à cette question ne pouvant pas tenir dans le modeste blog de Lexik.fr, je vais seulement vous expliquer comment intégrer la modification d&#8217;un champ &laquo;&nbsp;INPUT&nbsp;&raquo; en ajax dans un formulaire Symfony 1.2, à l&#8217;aide du plugin jQuery JEditable.</p>
<p>A ce stade, je vous recommande ce lien : <a href="http://www.appelsiini.net/projects/jeditable">JEditable</a><br />
<span id="more-502"></span></p>
<h2>Pré-requis</h2>
<ul>
<li>
Comme d&#8217;habitude, l&#8217;éternel plugin : <a href="http://www.symfony-project.org/plugins/sfFormExtraPlugin">sfFormExtraPlugin</a>
</li>
<li>
Les JS :</p>
<ul>
<li>jquery-1.3.2.min.js</li>
<li>jquery.jeditable.js</li>
</ul>
</li>
</ul>
<h2>Le widget</h2>
<p><b>Chemin : </b><br />
<quote>[votre_projet]/plugins/sfFormExtraPlugin/lib/widget/sfWidgetFormInputEditInPlace.class.php</quote>
</p>
<p><b>Code source :</b></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('p502code101'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502101"><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="p502code101"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormInputEditInPlace <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormInput
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$object</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$route</span><span style="color: #339933;">;</span>
  <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;">$option</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> <span style="color: #000088;">$messages</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> <span style="color: #000088;">$object</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$route</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$option</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messages</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;">object</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$object</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">route</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$route</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</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: #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: #339933;">,</span> <span style="color: #000088;">$messages</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>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messages</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</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> <span style="color: #000088;">$errors</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;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
&lt;b id=&quot;%s&quot;&gt;%s&lt;/b&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function() {
  $(&quot;#%s&quot;).editable(
    &quot;%s&quot;,
    {
      indicator : 'Saving...',      
      type   : &quot;text&quot;,
      submit : &quot;OK&quot;,
      style  : &quot;inherit&quot;,
      id       : 'ajaxfield_id'
  });
});
&lt;/script&gt;
EOF</span>
    <span style="color: #339933;">,</span> <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span>
      url_for<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">route</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">object</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;">'absolute'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #009900;">&#41;</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>

</p>
<p>Pour ce widget, j&#8217;ai créer 2 attributs.</p>
<ul>
<li><b>object</b><br />
Cet attribut contient l&#8217;objet de la route objet Symfony.</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('p502code102'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502102"><td class="line_numbers"><pre>4
</pre></td><td class="code" id="p502code102"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$object</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li><b>route</b><br />
Cet attribut contient le nom de la route objet Symfony.</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('p502code103'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502103"><td class="line_numbers"><pre>5
</pre></td><td class="code" id="p502code103"><pre class="php" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$route</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<p>Ces attributs nous permettent de générer l&#8217;URL de la page qui va valider et éventuellement sauvegarder les données postées par le widget JQuery.
</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('p502code104'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502104"><td class="line_numbers"><pre>36
</pre></td><td class="code" id="p502code104"><pre class="php" style="font-family:monospace;">url_for<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">route</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">object</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;">'absolute'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>
Maintenant que l&#8217;outil est créé, utilisons le !<br />
Toute la suite de l&#8217;article n&#8217;est qu&#8217;un exemple d&#8217;utilisation.
</p>
<h2>Schéma</h2>

<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('p502code105'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502105"><td class="code" id="p502code105"><pre class="yml" style="font-family:monospace;">Person:
  columns:
    firstname:
      type: string(255)
    lastname:
      type: string(255)
    email:
      type: string(255)</pre></td></tr></table></div>

<h2>Routing</h2>
<ul>
<li><b>show_person</b><br />
La route du formulaire.
</li>
<li><b>save_person_eip</b><br />
Route de l&#8217;action &laquo;&nbsp;executeSaveEIP&nbsp;&raquo; qui valide et sauve les champs du modèle &laquo;&nbsp;Person&nbsp;&raquo;
</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('p502code106'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502106"><td class="code" id="p502code106"><pre class="yml" style="font-family:monospace;"># Route du formulaire
show_person:
  url:     /person/show/:id
  class:   sfDoctrineRoute
  options: { model: Person, type: object }
  param:   { module: person, action: show }
&nbsp;
# Route de la page sauvant les données postées en ajax
save_person_eip:
  url:     /person/saveEIP/:id
  class:   sfDoctrineRoute
  options: { model: Person, type: object }
  param:   { module: person, action: saveEIP }
  requirements:
    id: d+
    sf_method: [post]</pre></td></tr></table></div>

<h2>Actions</h2>

<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('p502code107'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502107"><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
</pre></td><td class="code" id="p502code107"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// L'action pour le formulaire de base</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeShow<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</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;">person</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRoute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</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;">form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PersonForm<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</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;">// L'action qui traite le post en ajax</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeSaveEIP<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Récupération de l'objet de la route</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRoute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</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;">// Récupération des données postées par le widget JQuery</span>
  <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ajaxfield_id'</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;">value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Récupération du nom du champ</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/ereg"><span style="color: #990000;">ereg</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;person_(.*)$&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$champ</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Instanciation d'un formulaire lié à notre objet</span>
  <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PersonForm<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ération du validateur du champ</span>
  <span style="color: #000088;">$validator</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$champ</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// On tente de valider le champ</span>
  try
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$cleaned</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clean</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</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;">person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$champ</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</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;">joueur</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  catch<span style="color: #009900;">&#40;</span>sfValidatorError <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// Erreur lors de la validation du champ </span>
     <span style="color: #666666; font-style: italic;">// La valeur à afficher dans le template doit être la valeur actuelle de l'objet</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">person</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$champ</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>

<h2>Templates</h2>
<ul>
<li><b>showSuccess.php</b>

<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('p502code108'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502108"><td class="code" id="p502code108"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>Edition d<span style="color: #0000ff;">'une personne&lt;/h1&gt;
&lt;?php echo $form['</span>firstname<span style="color: #0000ff;">']-&gt;render();?&gt;&lt;br&gt;
&lt;?php echo $form['</span>lastname<span style="color: #0000ff;">']-&gt;render();?&gt;&lt;br&gt;
&lt;?php echo $form['</span>email<span style="color: #0000ff;">']-&gt;render();?&gt;&lt;br&gt;</span></pre></td></tr></table></div>

</li>
<li><b>saveEIPSuccess.php</b>

<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('p502code109'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502109"><td class="code" id="p502code109"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$value</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</li>
</ul>
<h2>Formulaire</h2>
<ul>
<li>
On construit chacun des widgets avec l&#8217;objet et le nom de la route.
</li>
<li>
On définit les validators.
</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('p502code110'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502110"><td class="code" id="p502code110"><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> configure<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;">// Widgets</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'firstname'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormEditInPlace<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: #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: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'save_joueur_eip'</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastname'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormEditInPlace<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: #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: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'save_joueur_eip'</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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormEditInPlace<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: #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: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'save_joueur_eip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Validators</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'firstname'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</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;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastname'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</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;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorEmail<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>

<h2>View.yml</h2>

<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('p502code111'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p502111"><td class="code" id="p502code111"><pre class="yml" style="font-family:monospace;">[...]
default:
  javascripts:    [jquery-1.3.2.min.js, jquery.jeditable.js]
[...]</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/jeditable-et-formulaire-symfony-12-502/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony &amp; jQuery DatePicker</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491#comments</comments>
		<pubDate>Tue, 14 Apr 2009 07:34:36 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[datePicker]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=491</guid>
		<description><![CDATA[Je vais vous montrer dans cet article comment mettre en place rapidement un datePicker jQuery dans un formulaire Symfony 1.2 Pré-requis Plugin sfFormExtraPlugin installé : sfFormExtraPlugin Fichiers externes Télécharger jQuery UI (jquery-1.3.2.min.js, jquery-ui-1.7.1.custom.min.js) Vous pouvez télécharger une version &#171;&#160;customizée&#160;&#187; de &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Je vais vous montrer dans cet article comment mettre en place rapidement un datePicker jQuery dans un formulaire Symfony 1.2</p>
<h2>Pré-requis</h2>
<ul>
<li>Plugin sfFormExtraPlugin installé : <a href="http://www.symfony-project.org/plugins/sfFormExtraPlugin">sfFormExtraPlugin</a>
</li>
</ul>
<p><span id="more-491"></span></p>
<h2>Fichiers externes</h2>
<ul>
<li>
<b>Télécharger jQuery UI </b><br />
<em>(jquery-1.3.2.min.js, jquery-ui-1.7.1.custom.min.js)</em></p>
<p>Vous pouvez télécharger une version &laquo;&nbsp;customizée&nbsp;&raquo; de jQuery UI ici :<br />
<a href="http://jqueryui.com/download">Télécharger JQuery UI</a>
</p>
</li>
<li>
<b>Version française</b><br />
<em>(uidatepicker-fr.js)</em></p>
<p>Vous trouverez le patch français de ce plugin ici :</p>
<p><a href="http://www.remy-solnais.com/jquery-et-datepicker/">Datepicker jQuery en français</a>
</li>
<li><b>Intégration dans Symfony</b>
<ol>
<li><b>JS</b><br />
  Copiez les fichiers :<br />
  <b>[jquery UI]/js/jquery-1.3.2.min.js </b><br />
  <b>[jquery UI]/js/jquery-ui-1.7.1.custom.min.js </b><br />
  <b>uidatepicker-fr.js</b><br />
  directement dans <b>[votre_projet]/web/js</b>
  </li>
<li><b>CSS</b>
<ul>
<li>Copiez le fichier :<br />
<b>[jquery UI]/css/jquery-ui-1.7.1.custom.css</b> dans :<br />
<b>[votre_projet]/web/css.</b>
</li>
<li><span style="color: red;">!! Attention !! </span>:<br />
J&#8217;ai dû remplacer toutes les occurrences de :<br />
<b>url(images/</b> par :<br />
<b>url(../images/</b>
</li>
</ul>
</li>
<li><b>Images</b><br />
N&#8217;oubliez pas de copier le contenu de :<br />
<b>[jquery UI]/css/smoothness/images</b> dans :<br />
<b>[votre_projet]/web/images</b>
</li>
</ol>
</li>
</ul>
<h2>View.yml</h2>
<p>N&#8217;oubliez pas de faire référence aux fichiers externes dans le view :</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('p491code120'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491120"><td class="code" id="p491code120"><pre class="yml" style="font-family:monospace;">default:
  http_metas:
    content-type: text/html
&nbsp;
  metas:
    #title:        symfony project
    #description:  symfony project
    #keywords:     symfony, project
    #language:     en
    #robots:       index, follow
&nbsp;
  stylesheets:    [main.css, jquery-ui-1.7.1.custom.css]
&nbsp;
  javascripts:    [jquery-1.3.2.min.js, uidatepicker-fr.js, jquery-ui-1.7.1.custom.min.js]
&nbsp;
  has_layout:     on
  layout:         layout</pre></td></tr></table></div>

<h2>sfWidgetFormJQueryI18nDate.class.php</h2>
<p>J&#8217;ai modifié la classe sfWidgetFormJQueryDate pour qu&#8217;elle soit compatible avec un format de date français.<br />
De plus, on peut facilement configurer les options  du widget jQuery.</p>
<ul>
<li><b>Code source :</b><br />
<u>Fichier :</u> sfWidgetFormJQueryI18nDate.class.php<br />
<u>Chemin :</u> /plugins/sfFormExtraPlugin/lib/widget/</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('p491code121'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491121"><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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
</pre></td><td class="code" id="p491code121"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier &lt;fabien.potencier@symfony-project.com&gt;
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * sfWidgetFormJQueryDate represents a date widget rendered by JQuery UI.
 *
 * This widget needs JQuery and JQuery UI to work.
 *
 * @package    symfony
 * @subpackage widget
 * @author     Fabien Potencier &lt;fabien.potencier@symfony-project.com&gt;
 * @version    SVN: $Id: sfWidgetFormJQueryDate.class.php 12875 2008-11-10 12:22:33Z fabien $
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormJQueryI18nDate <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormI18nDate
<span style="color: #009900;">&#123;</span>
  <span style="color: #009933; font-style: italic;">/**
   * Configures the current widget.
   *
   * Available options:
   *
   *  * image:   The image path to represent the widget (false by default)
   *  * config:  A JavaScript array that configures the JQuery date widget
   *  * culture: The user culture
   *
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetForm
   */</span>	
&nbsp;
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><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: #339933;">,</span> <span style="color: #000088;">$attributes</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><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#93;</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;culture&quot;</span><span style="color: #009900;">&#93;</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;years&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    parent<span style="color: #339933;">::</span><span style="color: #004000;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'en'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</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><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'en'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * @param  string $name        The element name
   * @param  string $value       The date displayed in this widget
   * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
   * @param  array  $errors      An array of errors for the field
   *
   * @return string An HTML tag string
   *
   * @see sfWidgetForm
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</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> <span style="color: #000088;">$errors</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;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', buttonImage: %s, buttonImageOnly: true'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image'</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;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</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;">renderTag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'input'</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;">'hidden'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_jquery_control'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disabled'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
           <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;
  function %s_read_linked()
  {
    \$(&quot;#%s&quot;).val(\$(&quot;#%s&quot;).val() + &quot;/&quot; + \$(&quot;#%s&quot;).val() + &quot;/&quot; + \$(&quot;#%s&quot;).val());
&nbsp;
    return {};
  }
&nbsp;
  function %s_update_linked(date)
  {
    \$(&quot;#%s&quot;).val(date.substring(0, 2));
    \$(&quot;#%s&quot;).val(parseInt(date.substring(3, 5), 10));
    \$(&quot;#%s&quot;).val(date.substring(6, 10));
  }
&nbsp;
  \$(&quot;#%s&quot;).datepicker(\$.extend({}, {
    minDate:    new Date(%s, 1 - 1, 1),
    maxDate:    new Date(%s, 12 - 1, 31),
    onSelect:   %s_update_linked,
    beforeShow: %s_read_linked,    
    %s    
    showOn:     &quot;both&quot;
    %s
  }, \$.datepicker.regional[&quot;%s&quot;]));
&nbsp;
&lt;/script&gt;
EOF</span>
      <span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[day]'</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;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[month]'</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;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[year]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[day]'</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;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[month]'</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;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'[year]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$id</span><span style="color: #339933;">,</span>
      <a href="http://www.php.net/min"><span style="color: #990000;">min</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/max"><span style="color: #990000;">max</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</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><b>Explication des modifications :</b>
<ol>
<li>
<b>Ligne 20 :</b><br />
Notre widget dérive désormais de sfWidgetForm<b>I18n</b>Date</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('p491code122'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491122"><td class="line_numbers"><pre>20
</pre></td><td class="code" id="p491code122"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormJQueryDate <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormI18nDate</pre></td></tr></table></div>

</li>
<li><b>Lignes 40, 41 et 42:</b><br />
On ajoute les options &laquo;&nbsp;config&nbsp;&raquo;, &laquo;&nbsp;culture&nbsp;&raquo; et &laquo;&nbsp;years&nbsp;&raquo; avec le paramètre &laquo;&nbsp;options&nbsp;&raquo; de la fonction &laquo;&nbsp;configure&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('p491code123'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491123"><td class="line_numbers"><pre>40
41
42
</pre></td><td class="code" id="p491code123"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;config&quot;</span><span style="color: #009900;">&#93;</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;culture&quot;</span><span style="color: #009900;">&#93;</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'years'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;years&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li><b>Lignes 85 et 86</b>
<ul>
<li>Il faut inverser l&#8217;ordre du jour et du mois pour être compatible avec un format français, ce qui revient dans un <a href="http://fr.php.net/sprintf">sprintf</a>, à changer l&#8217;ordre des lignes dans le code.
</li>
<li>Il faut faire un <a href="http://www.w3schools.com/jsref/jsref_parseInt.asp">parseInt</a> sur le mois pour transformer &laquo;&nbsp;01&#8243; en &laquo;&nbsp;1&#8243;, parseInt est la fonction javascript permettant de caster une chaîne de caractères en Integer :<br />
Premier paramètre : la chaîne à caster (ici : date.substring(3, 5) )<br />
Deuxième paramètre : Le système numérique à utiliser (ici décimal : 10)
</li>
</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('p491code124'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491124"><td class="line_numbers"><pre>85
86
</pre></td><td class="code" id="p491code124"><pre class="php" style="font-family:monospace;">    \$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#<span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    \$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#<span style="color: #009933; font-weight: bold;">%s</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span><a href="http://www.php.net/date"><span style="color: #990000;">date</span></a><span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li><b>Lignes 95 et 109</b>
<ul>
<li>On passe les options directement dans le premier argument.<br />
Le <b>%s</b> de la ligne 95 correspond au  <b>$this->getOption(&#8216;config&#8217;)</b> de la  ligne 109<br />
Le <b>%s</b> de la ligne 98 correspond au  <b>$this->getOption(&#8216;culture&#8217;)</b> de la  ligne 109
</li>
<li>Ligne 109 : passage des options et da la culture au widget.
</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('p491code125'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491125"><td class="line_numbers"><pre>108
</pre></td><td class="code" id="p491code125"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prefix</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'culture'</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

</li>
</ul>
</li>
</ol>
<h2>Exemple d&#8217;utilisation</h2>
<ul>
<li><b>Schéma</b>

<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('p491code126'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491126"><td class="code" id="p491code126"><pre class="yml" style="font-family:monospace;">person:
  columns:
    [...]
    birthday:
      type: timestamp
    [...]</pre></td></tr></table></div>

</li>
<li><b>Formulaire (Instanciation du widget)</b>

<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('p491code127'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p491127"><td class="code" id="p491code127"><pre class="php" style="font-family:monospace;">  <span style="color: #009900;">&#91;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#93;</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: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1900</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">2010</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: #000088;">$years</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: #000088;">$i</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'birthday'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormJQueryI18nDate<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;">'config'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yearRange: \'1900:2009\', 
                           changeYear: true, 
                           changeMonth: true,'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'culture'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fr'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'years'</span><span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array_combine"><span style="color: #990000;">array_combine</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span><span style="color: #339933;">,</span> <span style="color: #000088;">$years</span><span style="color: #009900;">&#41;</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;">&#91;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

</li>
<li><b>Aperçu</b><br />
<img src="http://img152.imageshack.us/img152/8430/jquerydatepickerfr.jpg" title="jquery datepicker fr" alt="jquery datepicker fr" width="450">
</li>
</ul>
<hr />
<h2>Sources</h2>
<ul>
<li>
<em><a href="http://www.symfony-project.org/forms/1_2/en/08-Internationalisation-and-Localisation">Symfony Internationalisation and Localisation</a></em>
</li>
<li>
<em><a href="http://www.symfony-project.org/forms/1_2/en/A-Widgets">Symfony Widgets</a></em>
</li>
<li>
<em><a href="http://jqueryui.com/">jQuery UI</a></em>
</li>
<li>
<em><a href="http://www.remy-solnais.com/jquery-et-datepicker/">Remy Solnais jquery et datepicker en Français</a></em>
</li>
<li>
<em><a href="http://www.w3schools.com/jsref/jsref_parseInt.asp">W3schools parseInt en Javascript</a></em>
</li>
<li>
<em><a href="http://fr.php.net/sprintf">PHP.net fonction sprintf</a></em>
</li>
<li>
<em><a href="http://imageshack.us/">ImageShack</a></em>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/symfony-jquery-datepicker-491/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Formulaire symfony 1.2 non lié à un modèle</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/formulaire-symfony-12-pas-lie-a-un-modele-215</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/formulaire-symfony-12-pas-lie-a-un-modele-215#comments</comments>
		<pubDate>Wed, 01 Apr 2009 12:24:51 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=215</guid>
		<description><![CDATA[Pour créer un formulaire qui n&#8217;est pas lié à un modèle, il suffit simplement de créer une classe dérivant de sfForm dans le répertoire : lib/form/doctrine. Ensuite, vous déclarez le formulaire dans l&#8217;action et vous l&#8217;affichez dans le template. Symfony &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/formulaire-symfony-12-pas-lie-a-un-modele-215">...</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.symfony-project.org/book/forms/"></a>Pour créer un formulaire qui n&#8217;est pas lié à un modèle, il suffit simplement de créer une classe dérivant de sfForm dans le répertoire : lib/form/doctrine.<br />
Ensuite, vous déclarez le formulaire dans l&#8217;action et vous l&#8217;affichez dans le template.<br />
Symfony propose un manuel détaillé sur les formulaires 1.2 ici :<br />
<a href="http://www.symfony-project.org/book/forms/1_2/">Formulaires symfony 1.2</a><br />
<span id="more-215"></span><br />
Le principal exemple est la création d&#8217;un formulaire de contact qui n&#8217;est pas stocké en base de données, et donc qui n&#8217;a pas de modèle ni de formulaire généré.</p>
<h2>Classe formulaire</h2>
<p>Définition des widgets et des validators.</p>
<h2>Action</h2>
<p>Déclaration du formulaire.<br />
ex :</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('p215code130'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p215130"><td class="code" id="p215code130"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>form <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ContactForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Template</h2>
<p>Affichage.<br />
ex :</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('p215code131'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p215131"><td class="code" id="p215code131"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?php echo url_for('contact/index') ?&amp;gt;&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/formulaire-symfony-12-pas-lie-a-un-modele-215/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FCKeditor dans l&#8217;admin generator (Symfony 1.2, Doctrine)</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/fck-editor-dans-ladmin-generator-symfony-12-doctrine-262</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/fck-editor-dans-ladmin-generator-symfony-12-doctrine-262#comments</comments>
		<pubDate>Sat, 14 Mar 2009 18:35:49 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Admingenerator 1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[admin generator]]></category>
		<category><![CDATA[fckeditor]]></category>
		<category><![CDATA[fichier]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=262</guid>
		<description><![CDATA[Mise en place d&#8217;un &#171;&#160;éditeur de texte riche&#160;&#187; (FCKeditor) dans l&#8217;admin generator d&#8217;un projet Symfony 1.2 (Doctrine) Pré-requis : Le lien qui m&#8217;a permis de faire ce post : http://trac.symfony-project.org/wiki/HowToUseFCKeditor Un module admin doctrine nommé ici &#171;&#160;contenu&#160;&#187;, avec un champ &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/fck-editor-dans-ladmin-generator-symfony-12-doctrine-262">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Mise en place d&#8217;un &laquo;&nbsp;éditeur de texte riche&nbsp;&raquo; (FCKeditor) dans l&#8217;admin generator d&#8217;un projet Symfony 1.2 (Doctrine)<br />
<span id="more-262"></span></p>
<h2>Pré-requis :</h2>
<ul>
<li> Le lien qui m&#8217;a permis de faire ce post :<br />
<a href="http://trac.symfony-project.org/wiki/HowToUseFCKeditor">http://trac.symfony-project.org/wiki/HowToUseFCKeditor</a></li>
<li> Un module admin doctrine nommé ici &laquo;&nbsp;contenu&nbsp;&raquo;, avec un champ nommé &laquo;&nbsp;html&nbsp;&raquo; de type CLOB</li>
<li> Le plugin sfFormExtraPlugin installé (<a href="http://www.symfony-project.org/plugins/sfFormExtraPlugin">http://www.symfony-project.org/plugins/sfFormExtraPlugin</a>)</li>
</ul>
<h2>Intégrer FCK</h2>
<ul>
<li> Télécharger les fichiers<br />
<a href="http://www.fckeditor.net/download">http://www.fckeditor.net/download</a></li>
<li> Copier les dans web/js/fckeditor</li>
<li> Modifier<br />
<blockquote><p>/apps/backend/config/settings.yml</p></blockquote>

<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('p262code140'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262140"><td class="code" id="p262code140"><pre class="yaml" style="font-family:monospace;">...
.settings:
  rich_text_fck_js_dir: js/fckeditor
...</pre></td></tr></table></div>

</li>
</ul>
<h2>Créer un nouveau widget pour sfFormExtraPlugin</h2>
<p>Créer ce fichier :</p>
<blockquote><p>/plugin/sfFormExtraPlugin/lib/widget/sfWidgetFormTextareaFCK.class.php</p></blockquote>

<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('p262code141'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262141"><td class="code" id="p262code141"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
    * FCK Form widget
    *
    * @package    ***
    * @subpackage lib
    * @author     $LastChangedBy: PoWl $
    * @version    SVN: $Id: sfWidgetFormTextareaFCK.class.php 81 2008-12-08 00:39:59Z PoWl $
    */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormTextareaFCK <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormTextarea
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
        * @param array $options     An array of options
        * @param array $attributes  An array of default HTML attributes
        *
        * @see sfWidgetForm
        */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> configure <span style="color: #009900;">&#40;</span><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: #339933;">,</span> <span style="color: #000088;">$attributes</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><span style="color: #004000;">addOption</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'fck'</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;">addOption</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'css'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        parent<span style="color: #339933;">::</span><span style="color: #004000;">configure</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
        * @param  string $name        The element name
        * @param  string $value       The value displayed in this widget
        * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
        * @param  array  $errors      An array of errors for the field
        *
        * @return string An HTML tag string
        *
        * @see sfWidgetForm
        */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render <span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</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> <span style="color: #000088;">$errors</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;">$editorClass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'sfRichTextEditorFCK'</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/class_exists"><span style="color: #990000;">class_exists</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$editorClass</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> sfConfigurationException <span style="color: #009900;">&#40;</span><a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The rich text editor &quot;%s&quot; does not exist.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$editorClass</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: #000088;">$editor</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$editorClass</span> <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: #339933;">!</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sfRichTextEditor'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/class_parents"><span style="color: #990000;">class_parents</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$editor</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>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> sfConfigurationException <span style="color: #009900;">&#40;</span><a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The editor &quot;%s&quot; must extend sfRichTextEditor.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$editor</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: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</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;">$editor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialize</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$editor</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toHTML</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: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>J&#8217;ai fait trois modifications dans le fichier proposé par le site dont je donne le lien plus haut :</p>
<ol>
<li> Ligne 1 : Attention au cas ou le short tag n&#8217;est pas activé</li>
<li> Standardisation du nom de la classe (sfWidgetFormTextareaFCK)</li>
<li> Ligne 49 : Il faut modifier cette ligne pour pouvoir passer des attributs HTML par defaut au widget:

<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('p262code142'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262142"><td class="code" id="p262code142"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOptions</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
</ol>
<h2>Utilisation</h2>
<p>Modifier le formulaire de Contenu :</p>
<blockquote><p>/lib/form/doctrine/ContenuForm.class.php</p></blockquote>

<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('p262code143'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262143"><td class="code" id="p262code143"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextareaFCK<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: #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;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'700'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'800'</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #339933;">...</span></pre></td></tr></table></div>

<h2>Configurer l&#8217;upload de fichiers</h2>
<p>Remplacer le fichier situé dans :</p>
<blockquote><p>/web/js/fckeditor/editor/filemanager/connectors/php/config.php</p></blockquote>
<p>Par celui-là :</p>
<p><a href="http://trac.symfony-project.org/attachment/wiki/HowToUseFCKeditor/config.new">http://trac.symfony-project.org/attachment/wiki/HowToUseFCKeditor/config.new</a></p>
<ol> Il y a 2 lignes importantes :</p>
<li> UserFilesPath

<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('p262code144'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262144"><td class="code" id="p262code144"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesPath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'userfiles'</span> <span style="color: #339933;">.</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>que l&#8217;on transforme 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('p262code145'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262145"><td class="code" id="p262code145"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesPath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">/</span>uploads<span style="color: #339933;">/</span>fck<span style="color: #339933;">/</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li> UserFilesAbsolutePath

<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('p262code146'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262146"><td class="code" id="p262code146"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesAbsolutePath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span>DOCUMENT_ROOT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesPath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Qu&#8217;il vous faut éventuellement modifier si la racine de votre projet n&#8217;est pas la même que celle de votre serveur:</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('p262code147'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p262147"><td class="code" id="p262code147"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesAbsolutePath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span>DOCUMENT_ROOT<span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #339933;">/</span>myProject<span style="color: #339933;">/</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesPath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
</ol>
<hr /><em><br />
Sources :</em></p>
<ul>
<li> <em><a href="http://trac.symfony-project.org/wiki/HowToUseFCKeditor">http://trac.symfony-project.org/wiki/HowToUseFCKeditor</a> </em></li>
<li> <em><a href="http://www.symfony-project.org/plugins/sfFormExtraPlugin">http://www.symfony-project.org/plugins/sfFormExtraPlugin</a> </em></li>
<li> <em><a href="http://www.fckeditor.net/download">http://www.fckeditor.net/download</a> </em></li>
</ul>
<p><em> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/fck-editor-dans-ladmin-generator-symfony-12-doctrine-262/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Configurer Ubuntu pour envoyer des mails PHP à la sauce sendmail sans sendmail !</title>
		<link>http://www.lexik.fr/blog/symfony/ubuntu/configurer-ubuntu-pour-envoyer-des-mails-php-a-la-sauce-sendmail-sans-sendmail-237</link>
		<comments>http://www.lexik.fr/blog/symfony/ubuntu/configurer-ubuntu-pour-envoyer-des-mails-php-a-la-sauce-sendmail-sans-sendmail-237#comments</comments>
		<pubDate>Fri, 13 Mar 2009 17:03:14 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ubuntu php email]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=237</guid>
		<description><![CDATA[Sur windows la fonction mail() de php est configurée pour fonctionner via SMTP que l&#8217;on peut configurer dans le php.ini Sur les systèmes Linux, ça n&#8217;est pas le cas. Php est configuré pour transmettre les mails via un vrai service &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/ubuntu/configurer-ubuntu-pour-envoyer-des-mails-php-a-la-sauce-sendmail-sans-sendmail-237">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Sur windows la fonction mail() de php est configurée pour fonctionner via SMTP que l&#8217;on peut configurer dans le php.ini</p>
<p>Sur les systèmes Linux, ça n&#8217;est pas le cas. Php est configuré pour transmettre les mails via un vrai service de transport de mail du style sendmail ou postfix.<br />
Le problème de ces programmes (demon), c&#8217;est qu&#8217;ils ne sont pas évidents à installer et configurer correctement pour tout les développeurs qui ne sont pas admin système.<span id="more-237"></span></p>
<p>Heureusement ESMTP est là pour nous sauver, nous autres simples développeurs.</p>
<blockquote><p><strong>Esmtp is a send-only sendmail emulator</strong></p></blockquote>
<p>Pour les anglophobes, ESMTP est un émulateur de sendmail pour l&#8217;envoi seulement des mails.<br />
C&#8217;est à dire que c&#8217;est un programme qui comprend les commandes sendmail, les traduit en requêtes smtp et les transmet à un serveur smtp.</p>
<h2>Installation et configuration de ESMTP</h2>

<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('p237code152'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p237152"><td class="code" id="p237code152"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> esmtp</pre></td></tr></table></div>

<p>Ou alors, vous le trouverez dans Synaptic.</p>
<p>Aprés quoi un petit coup de</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('p237code153'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p237153"><td class="code" id="p237code153"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>esmtprc</pre></td></tr></table></div>

<p>pour aller modifier la configuration et mettre le stmp que l&#8217;on veut utiliser (celui de votre provider).</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('p237code154'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p237154"><td class="code" id="p237code154"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Config file for ESMTP sendmail</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The SMTP host and service (port)</span>
<span style="color: #007800;">hostname</span>=smtp.orange.fr:<span style="color: #000000;">25</span></pre></td></tr></table></div>

<p>Dernier petit point à voir, faire un lien symbolique de sendmail vers esmtp pour faire croire à php que sendmail est installé.</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('p237code155'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p237155"><td class="code" id="p237code155"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>esmtp <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sendmail</span></pre></td></tr></table></div>

<p>Et voila ! Vous pouvez coder des envois de mails, dans des conditions de production, avec la méthode sendmail sans avoir eu à passer des heures à configurer votre serveur de mail <img src='http://www.lexik.fr/blog/symfony/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Source : <a href="http://esmtp.sourceforge.net/">http://esmtp.sourceforge.net/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/ubuntu/configurer-ubuntu-pour-envoyer-des-mails-php-a-la-sauce-sendmail-sans-sendmail-237/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TinyMCE dans l&#8217;admin generator (Symfony 1.2, Doctrine)</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/sfformextraplugin-tinymce-197</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/sfformextraplugin-tinymce-197#comments</comments>
		<pubDate>Wed, 04 Mar 2009 22:58:26 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Admingenerator 1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rich text editor]]></category>
		<category><![CDATA[sfFormExtraPlugin]]></category>
		<category><![CDATA[tinyMCE]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=197</guid>
		<description><![CDATA[Comment mettre en place un &#171;&#160;Rich Text Editor&#160;&#187; dans un backend Symfony 1.2 doctrine ? J&#8217;ai trouvé la solution dans un post du forum symfony, je vous donne la version originale&#160;: http://forum.symfony-project.org/index.php/m/66906/?srch=tinymce+3+steps#msg_66906 En français et expliqué plus en détails, ça &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/sfformextraplugin-tinymce-197">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Comment mettre en place un &laquo;&nbsp;Rich Text Editor&nbsp;&raquo; dans un backend Symfony 1.2 doctrine ?<br />
J&#8217;ai trouvé la solution dans un post du forum symfony, je vous donne la version originale&nbsp;:<br />
<span id="more-197"></span></p>
<p><a href="http://forum.symfony-project.org/index.php/m/66906/?srch=tinymce+3+steps#msg_66906">http://forum.symfony-project.org/index.php/m/66906/?srch=tinymce+3+steps#msg_66906</a></p>
<p>En français et expliqué plus en détails, ça donne : </p>
<h2>Intégrer Tiny MCE</h2>
<ul>
<li>
Télécharger et copier :<br />
<a href="http://tinymce.moxiecode.com/download.php">http://tinymce.moxiecode.com/download.php</a><br />
dans :</p>
<blockquote><p>/web/js/tinyMCE</p></blockquote>
</li>
<li>
Modifier ce fichier :</p>
<blockquote><p>/apps/backend/config/settings.yml</p></blockquote>

<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('p197code160'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p197160"><td class="code" id="p197code160"><pre class="yml" style="font-family:monospace;">all:
  .settings:
    sf_rich_text_js_dir: js/tinyMCE</pre></td></tr></table></div>

</li>
</ul>
<h2>Installer le plugin sfFormExtraPlugin:</h2>

<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('p197code161'); return false;">View Code</a> SF</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p197161"><td class="code" id="p197code161"><pre class="sf" style="font-family:monospace;">symfony plugin:install sfFormExtraPlugin</pre></td></tr></table></div>

<h2>Modifier le widget sfWidgetFormTextareaTinyMCE.class.php</h2>
<p>Il faut modifier le plugin !</p>
<blockquote><p>/plugins/sfFormExtraPlugin/lib/widget/sfWidgetFormTextareaTinyMCE.class.php</p></blockquote>
<p>Fichier :</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('p197code162'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p197162"><td class="code" id="p197code162"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormTextareaTinyMCE <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormTextarea
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><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: #339933;">,</span> <span style="color: #000088;">$attributes</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><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theme'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'advanced'</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</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;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</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> <span style="color: #000088;">$errors</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;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #339933;">...</span></pre></td></tr></table></div>

<h2>Utilisation</h2>
<p>Modifier ce fichier :</p>
<blockquote><p>/lib/form/doctrine/ContenuForm.class.php</p></blockquote>

<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('p197code163'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p197163"><td class="code" id="p197code163"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> ContenuForm <span style="color: #000000; font-weight: bold;">extends</span> BaseContenuForm
<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;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'texte'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextareaTinyMCE<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;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">550</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">350</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'config'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'theme_advanced_disable: &quot;anchor,image,cleanup,help&quot;'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'theme'</span>   <span style="color: #339933;">=&gt;</span>  sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_tinymce_theme'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'advanced'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</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;">'class'</span>   <span style="color: #339933;">=&gt;</span>  <span style="color: #0000ff;">'tiny_mce'</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$js_path</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_rich_text_js_dir'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_rich_text_js_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/tiny_mce.js'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'/sf/tinymce/js/tiny_mce.js'</span><span style="color: #339933;">;</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;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addJavascript</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$js_path</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>

<hr />
<em><br />
Sources:</p>
<ul>
<li>
<a href="http://forum.symfony-project.org/index.php/m/66906/?srch=tinymce+3+steps#msg_66906">http://forum.symfony-project.org/index.php/m/66906/?srch=tinymce+3+steps#msg_66906</a>
</li>
<li>
<a href="http://tinymce.moxiecode.com/download.php">http://tinymce.moxiecode.com/download.php</a>
</li>
</ul>
<p></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/sfformextraplugin-tinymce-197/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

