<?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 Symfony - Lexik Montpellier &#187; doctrine</title>
	<atom:link href="http://www.lexik.fr/blog/symfony/tag/doctrine/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lexik.fr/blog/symfony</link>
	<description>Blog sur le développement Web PHP</description>
	<lastBuildDate>Tue, 20 Jul 2010 08:35:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Doctrine_Collection et hydration hiérarchisée.</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/doctrine_collection-et-hydration-hierarchisee-1109</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/doctrine_collection-et-hydration-hierarchisee-1109#comments</comments>
		<pubDate>Wed, 07 Apr 2010 07:51:10 +0000</pubDate>
		<dc:creator>yoye</dc:creator>
				<category><![CDATA[1.4.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[Doctrine_Collection]]></category>
		<category><![CDATA[Doctrine_Hydrator]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[nestedset]]></category>
		<category><![CDATA[toHierarchy]]></category>
		<category><![CDATA[treeTable]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1109</guid>
		<description><![CDATA[En ce moment nous sommes en train de travailler sur un site de collectionneurs et nous avons le plaisir de tomber sur quelques cas intéressants au niveau développement ce qui n&#8217;est pas pour nous déplaire. Ce site contient une grosse partie sur la gestion des zones géographiques, on a décidé d&#8217;utiliser le behavior Nestedset ce [...]]]></description>
			<content:encoded><![CDATA[<p>En ce moment nous sommes en train de travailler sur un site de collectionneurs et nous avons le plaisir de tomber sur quelques cas intéressants au niveau développement ce qui n&#8217;est pas pour nous déplaire. Ce site contient une grosse partie sur la gestion des zones géographiques, on a décidé d&#8217;utiliser le behavior Nestedset ce qui nous permet de gérer facilement les différentes arborescences : &laquo;&nbsp;Continent > Pays > état&nbsp;&raquo; ou &laquo;&nbsp;Continent > Pays > Région&nbsp;&raquo; ou encore &laquo;&nbsp;Continent > Pays / Ancien Pays&nbsp;&raquo;.<br />
<span id="more-1109"></span><br />
Je ne vais pas faire un point sur le nested, la <a href="http://www.lexik.fr/blog/symfony/symfony/nested-set-doctrine-135">gestion par arborescence</a> a déjà été abordée sur ce blog. En revanche je vais vous faire part d&#8217;une découverte récente. La possibilité d&#8217;hydrater directement une collection sous sa forme d&#8217;arbre.</p>
<p>Pour le listing de ces zones j&#8217;ai donc choisi d&#8217;utiliser un plugin jQuery : <a href="http://blog.cubicphuse.nl/2008/11/12/jquery-treetable-2-0">treeTable</a>. Comme son nom l&#8217;indique ce plugin va nous permettre une organisation d&#8217;un arbre dans une table HTML. Il faut indiquer en &laquo;&nbsp;id&nbsp;&raquo; de la balise<br />
<tr> de notre tableau un identifiant de notre objet (ex: id=&nbsp;&raquo;node-1&#8243;) et à l&#8217;attribut &laquo;&nbsp;class&nbsp;&raquo; on signale de qui le noeud est l&#8217;enfant (ex: child-of-node-1 sera le fils du noeud 1).</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('p1109code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11095"><td class="code" id="p1109code5"><pre class="php" style="font-family:monospace;">  <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;content-box-content&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>table id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tree&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tbody<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;">$areas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$area</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: #000088;">$parent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$area</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParent</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>tr id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;node-&lt;?php echo <span style="color: #006699; font-weight: bold;">$area-&gt;getId</span>() ?&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$parent</span> ? <span style="color: #0000ff;">'class=&quot;child-of-node-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$parent</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;">'&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #990000;">echo</span> <span style="color: #000088;">$area</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: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'module_area_list_action_add_children'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'area_new'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$area</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'parent_id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$area</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: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
          <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> link_to<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text_action_delete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'@area_delete?id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$area</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: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'confirm'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text_action_delete_confirm'</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>td<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>tr<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: #000000; font-weight: bold;">?&gt;</span>
      <span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Voici le résultat : </p>
<p><img src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/04/treeTableArea1.png" alt="treeTableArea" title="treeTableArea" width="975" height="528" class="alignnone size-full wp-image-1115" /></p>
<p>Le rendu correspond à ce que souhaite mon client, lorsque l&#8217;on clique sur une branche, par exemple Afrique ou Europe les lignes suivantes se déplient et laissent apparaitre les enfants. Tout va pour le mieux dans le meilleur des mondes, simplement quand on regarde de plus près on s&#8217;aperçoit que pour un listing de simplement 12 zones je fais 29 requêtes, que va t&#8217;il se passer lorsque je vais avoir toutes mes zones renseignées, la réponse est : +700 requêtes. Le souci vient de la méthode <a href="http://www.doctrine-project.org/Doctrine_Node_NestedSet/1_2#method_getparent">getNode()->getParent()</a> qui exécute une nouvelle requête à chaque appel. En effet pour lier une ligne à son parent j&#8217;ai besoin de connaître l&#8217;ID du père.</p>
<p>Pour remédier à cela je vais donc utiliser l&#8217;Hydratation hiérarchisée, que l&#8217;on peut créer à l&#8217;aide d&#8217;une Doctrine_Query qu&#8217;on exécutera comme suit :</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('p1109code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11096"><td class="code" id="p1109code6"><pre class="php" style="font-family:monospace;">Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Area'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>
   <span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span>
  execute<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> Doctrine_Core<span style="color: #339933;">::</span><span style="color: #004000;">HYDRATE_RECORD_HIERARCHY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Sinon on peut directement utiliser la méthode toHierarchy() sur notre collection, qui nous hydratera directement cette dernière. Chaque élément contenant alors des enfants aura une clé __children, qui n&#8217;est autre qu&#8217;un tableau des éléments enfants.</p>
<p>Je vais donc remplacer mon code et utiliser un helper pour le rendu d&#8217;une ligne ce qui permettra de faire de la récursivité plus facilement dans mon code.</p>
<p>Je crée donc l&#8217;helper suivant :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1109code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11097"><td class="code" id="p1109code7"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// apps/backend/lib/helper/AreaHierarchyHelper.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Permet l'affichage en arbre dans le listing des zones
 *
 * @param Area $area
 * @param int $parent
 * @return string
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> render_row<span style="color: #009900;">&#40;</span><span style="color: #000088;">$area</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parent</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Formatage du HTML</span>
  <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
&lt;tr id=&quot;node-%s&quot;%s&gt;
  &lt;td&gt;%s&lt;/td&gt;
  &lt;td&gt;%s&lt;/td&gt;
  &lt;td&gt;%s&lt;/td&gt;
  &lt;td&gt;%s&lt;/td&gt;
  &lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;'</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$area</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: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$parent</span> ? <span style="color: #0000ff;">''</span> <span style="color: #339933;">:</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' class=&quot;child-of-node-%s&quot;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$parent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #000088;">$area</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: #339933;">,</span>
      <span style="color: #0000ff;">'ID : '</span><span style="color: #339933;">.</span><span style="color: #000088;">$area</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>
      link_to<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'module_area_list_action_add_children'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'area_new'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$area</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'parent_id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$area</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: #009900;">&#41;</span><span style="color: #339933;">,</span>
      link_to<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text_action_edit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'area_edit'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$area</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'area-edit'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      link_to<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text_action_delete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'@area_delete?id='</span><span style="color: #339933;">.</span><span style="color: #000088;">$area</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: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'confirm'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'text_action_delete_confirm'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Récursivité pour créer les lignes des fils</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$area</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'__children'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> render_row<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">,</span> <span style="color: #000088;">$area</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: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Désormais sur ma page, il me suffit de charger mon helper et d&#8217;écrire le code suivant :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1109code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p11098"><td class="code" id="p1109code8"><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;">'AreaHierarchy'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<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;content-box&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;content-box-header&quot;</span><span style="color: #339933;">&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: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content-box-content&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>table id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tree&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tbody<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;">$areas</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toHierarchy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$area</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: #990000;">echo</span> render_row<span style="color: #009900;">&#40;</span><span style="color: #000088;">$area</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> <span style="color: #b1b100;">endforeach</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      <span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&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></pre></td></tr></table></div>

<p>Le résultat est exactement le même au niveau de l&#8217;affichage en revanche je passe désormais à 5 requêtes et sur les données définitives,  j&#8217;obtiens toujours 5 requêtes et ce quelque soit le nombre de résultat dans ma collection. J&#8217;ai donc bénéficié des avantages de Doctrine et surtout des Doctrine_Hydrator pour diminuer le nombre de requêtes. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/doctrine_collection-et-hydration-hierarchisee-1109/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>sfLexikDoctrineActAsCommentablePlugin ou comment rendre des objets commentables via un behavior / plugin</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/sflexikdoctrineactascommentableplugin-ou-comment-rendre-des-objets-commentables-via-un-behavior-plugin-1002</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/sflexikdoctrineactascommentableplugin-ou-comment-rendre-des-objets-commentables-via-un-behavior-plugin-1002#comments</comments>
		<pubDate>Mon, 09 Nov 2009 10:39:52 +0000</pubDate>
		<dc:creator>Nikaw</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[behavior]]></category>
		<category><![CDATA[commentable]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1002</guid>
		<description><![CDATA[Aujourd&#8217;hui je vais vous montrer comment rendre des objets commentables grâce à un behavior Doctrine que j&#8217;ai créé, et le plugin qui permet de l&#8217;exploiter. Le behavior donne les fonctionnalités, le plugin donne le modèle et l&#8217;affichage ainsi que les actions (listing des commentaires, formulaire d&#8217;ajout de commentaire, &#8230;) Je me suis basé sur le [...]]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui je vais vous montrer comment rendre des objets commentables grâce à un behavior Doctrine que j&#8217;ai créé, et le plugin qui permet de l&#8217;exploiter.</p>
<p>Le behavior donne les fonctionnalités, le plugin donne le modèle et l&#8217;affichage ainsi que les actions (listing des commentaires, formulaire d&#8217;ajout de commentaire, &#8230;)</p>
<p>Je me suis basé sur le behavior Doctrine Taggable fourni à l&#8217;origine pour réaliser ceci.</p>
<p>Le behavior et le plugin ne sont pas utilisable l&#8217;un sans l&#8217;autre.</p>
<p><span id="more-1002"></span><br />
télécharger les <a href='http://www.lexik.fr/blog/symfony/wp-content/uploads/2009/11/sfLexikDoctrineActAsCommentablePlugin.tar1.gz'>sources</a></p>
<p><strong>Fourni par le behavior :</strong></p>
<p>Le listener :</p>
<p>void postDelete(event) //supprime tous les commentaires liés lors de la suppression de l&#8217;objet les portant</p>
<p>Le template et ses méthodes :</p>
<p>void addComment(Comment) //ajoute le commentaire à l&#8217;objet</p>
<p>void deleteComments() //supprime tous les commentaires reliés à l&#8217;objet</p>
<p>Doctrine_Collection findComments(array $params, array $orders) //retourne tous les commentaires liés à l&#8217;objet, respectant les paramètres du tableau params, et classés successivement dans les ordres donnés par le tableau orders</p>
<p>int getNbComments() //retourne le nombre de commentaires liés à l&#8217;objet</p>
<p>CommentForm getCommentForm()</p>
<p><strong>Fourni par le plugin :</strong></p>
<p>La classe Comment :</p>
<p>getParent() pour récupérer l&#8217;objet porteur du commentaire</p>
<p>La classe CommentTable :</p>
<p>getCommentsFilteredQuery($params, $orders) pour récupérer une requête permettant de retrouver une collection de commentaires selon certains paramètres, et en respectant une suite d&#8217;ordres</p>
<p>getUnmoderatedCommentsQuery() pour récupérer une requête permettant de retrouver la collection des commentaires non modérés</p>
<p>getSpamCommentsQuery() pour récupérer la collection des commentaires classés spam<br />
Le modèle de donné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('p1002code13'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p100213"><td class="code" id="p1002code13"><pre class="yaml" style="font-family:monospace;">Comment:
  tableName: sf_comment
&nbsp;
  actAs: [Timestampable]
&nbsp;
  columns:
    user_id:
      type: integer(4)
&nbsp;
    #nom de l'auteur
    author_name:
      type: string(255)
      default: Anonyme
    #email de l'auter
    author_mail:
      type: string(255)
    #site web de l'auteur
    author_website:
      type: string(255)
&nbsp;
    #texte du commentaire
    text:
      type: clob
&nbsp;
    #id de l'objet porteur du commentaire
    parent_id:
      type: integer
    #classe de l'objet porteur du commentaire
    parent_class_name:
      type: string(255)
&nbsp;
    #publié ?
    is_published:
      type: boolean
      notnull: true
      default: true
    #modéré ?
    is_moderated:
      type: boolean
      notnull: true
      default: false
    #est un spam ?
    is_spam:
      type: boolean
      notnull: true
      default: false
&nbsp;
  relations:
    sfGuardUser:
      type: one
      foreignType: many
      local: user_id
      foreign: id
      foreignAlias: Comments</pre></td></tr></table></div>

<p>La technique pour relier un objet à cette table Comment est d&#8217;utiliser 2 champs spéciaux : parent_class_name et parent_id qui contiennent le nom de la classe ainsi que l&#8217;identifiant en base de l&#8217;objet porteur du commentaire.</p>
<p>De cette manière, on perd en partie l&#8217;aspect relationnel de la base, mais on allège énormément les requêtes de listing (derniers commentaires toutes catégories confondues, commentaires reliés à un objet, reliés à un type d&#8217;objet, &#8230;).<br />
Comment ça marche :</p>
<p>télécharger les <a href='http://www.lexik.fr/blog/symfony/wp-content/uploads/2009/11/sfLexikDoctrineActAsCommentablePlugin.tar1.gz'>sources</a><br />
Avant de commencer, il faut évidemment copié les sources du plugin dans le répertoire plugin/ de votre projet, puis :</p>
<p>php symfony plugin:publish-assets</p>
<p>Tout d&#8217;abord, il faut activer le module dans les settings, en l&#8217;ajoutant 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('p1002code14'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p100214"><td class="code" id="p1002code14"><pre class="yaml" style="font-family:monospace;">all:
  .settings:
    enabled_modules: [default, sfGuardAuth, sfGuardUser, comment]</pre></td></tr></table></div>

<p>Ensuite dans le schema.yml du projet, il faut spécifier le behavior sur l&#8217;objet :</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('p1002code15'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p100215"><td class="code" id="p1002code15"><pre class="yaml" style="font-family:monospace;">Message:
  actAs:
    Timestampable: ~
    Commentable: ~
  columns:
    …</pre></td></tr></table></div>

<p>A partir de là, on utilisera les fonctions et méthodes vues plus haut (fournies par le template).</p>
<p>Le plugin fournit des partials pour l&#8217;affichage par défaut, personnalisable via les noms de classes et id passables en paramètres (toutes les classes et id sont définies par défaut si pas d&#8217;options) :</p>
<p>Partial show_comment, paramètres :<br />
  $comment : le message à afficher<br />
  $options : les options spécifiques pour css personnalisé<br />
    show_comment_class → conteneur global<br />
    infos_class → entete (auteur, date et heure)<br />
    author_name_class → auteur<br />
    time_and_date_class → date et heure<br />
    date_class → date<br />
    time_class → heure<br />
    text_class → corps du commentaire</p>
<p>Partial comments_list, paramètres : (boucle sur le partial show_comment, donc passer en parametre les options pour le show_comment)<br />
  $comments : la liste des messages à afficher<br />
  $options : les options spécifiques pour css personnalisé<br />
    list_comment_class : classe de la div conteneur<br />
    list_comment_id : id de la div conteneur</p>
<p>Partial form_comment, paramètres :<br />
  $form : le formulaire<br />
  $action : l&#8217;action du formulaire, définie par défaut<br />
  $options : les options spécifiques pour css personnalisé<br />
    id → id du formulaire<br />
    class → classe du formulaire</p>
<p>Partial ajax_script, paramètres : script jquery permettant de valider le formulaire en ajax<br />
  $form : le formulaire</p>
<p>Partial ajax_form_comment, paramètres : le formulaire et le script ajax</p>
<p>Exemple d&#8217;utilisation :</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('p1002code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p100216"><td class="code" id="p1002code16"><pre class="php" style="font-family:monospace;">  <span style="color: #339933;">&lt;!--</span> <span style="color: #666666; font-style: italic;">// liste des commentaires du message --&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> include_partial<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment/comments_list'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comments'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findComments</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'created_at DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'options'</span><span style="color: #339933;">=&gt;</span>array<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>
&nbsp;
  <span style="color: #339933;">&lt;!--</span> <span style="color: #666666; font-style: italic;">// formulaire d'ajout de commentaire --&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&lt;?php echo <span style="color: #006699; font-weight: bold;">$message-&gt;getId</span>() ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>Postez votre commentaire <span style="color: #339933;">:&lt;/</span>h2<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;">'comment/ajax_form_comment'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCommentForm</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></pre></td></tr></table></div>

<p>Vous aurez noté qu&#8217;on ne parle pas encore de l&#8217;administration dans ce post, dans les publications à venir je vous parlerai d&#8217;abord du backend pour les commentaires, puis de la réalisation d&#8217;un behavior étape par étape.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/sflexikdoctrineactascommentableplugin-ou-comment-rendre-des-objets-commentables-via-un-behavior-plugin-1002/feed</wfw:commentRss>
		<slash:comments>4</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 12:01:50 +0000</pubDate>
		<dc:creator>olivier</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 associés aux utilisateurs, la possibilité de gérer des groupes le tout générant automatiquement les crédentials [...]]]></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('p634code25'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63425"><td class="code" id="p634code25"><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('p634code26'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63426"><td class="code" id="p634code26"><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('p634code27'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63427"><td class="code" id="p634code27"><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('p634code28'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63428"><td class="code" id="p634code28"><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('p634code29'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63429"><td class="code" id="p634code29"><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('p634code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63430"><td class="code" id="p634code30"><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('p634code31'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63431"><td class="code" id="p634code31"><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('p634code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p63432"><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="p634code32"><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>
    <span style="color: #990000;">unset</span><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><span style="color: #990000;">array</span><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><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><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\'</span>est pas valide<span style="color: #339933;">.</span><span style="color: #0000ff;">', '</span>required<span style="color: #0000ff;">' =&gt; '</span>Champ obligatoire<span style="color: #339933;">.</span><span style="color: #0000ff;">'));
    $this-&gt;validatorSchema['</span>password<span style="color: #0000ff;">']     = new sfValidatorString(array('</span>required<span style="color: #0000ff;">' =&gt; true, '</span>min_length<span style="color: #0000ff;">' =&gt; 6), array('</span>min_length<span style="color: #0000ff;">' =&gt; '</span><span style="color: #0000ff;">&quot;%value%&quot;</span> est trop court <span style="color: #009900;">&#40;</span><span style="color: #339933;">%</span>min_length<span style="color: #339933;">%</span> lettres minimum<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">', '</span>required<span style="color: #0000ff;">' =&gt; '</span>Champ obligatoire<span style="color: #339933;">.</span><span style="color: #0000ff;">'));
    $this-&gt;validatorSchema['</span>password_bis<span style="color: #0000ff;">'] = new sfValidatorString(array('</span>required<span style="color: #0000ff;">' =&gt; true, '</span>min_length<span style="color: #0000ff;">' =&gt; 6), array('</span>min_length<span style="color: #0000ff;">' =&gt; '</span><span style="color: #0000ff;">&quot;%value%&quot;</span> est trop court <span style="color: #009900;">&#40;</span><span style="color: #339933;">%</span>min_length<span style="color: #339933;">%</span> lettres minimum<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">', '</span>required<span style="color: #0000ff;">' =&gt; '</span>Champ obligatoire<span style="color: #339933;">.</span><span style="color: #0000ff;">'));
&nbsp;
    $this-&gt;mergePostValidator(new sfValidatorSchemaCompare(
      '</span>password<span style="color: #0000ff;">',
      sfValidatorSchemaCompare::EQUAL,
      '</span>password_bis<span style="color: #0000ff;">',
      array(),
      array('</span>invalid<span style="color: #0000ff;">' =&gt; '</span>Les champs doivent être identiques<span style="color: #339933;">.</span><span style="color: #0000ff;">')
    ));
  }
&nbsp;
}</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>4</slash:comments>
		</item>
		<item>
		<title>Colonnes de recherche perso dans le filter de l&#8217;admin generator, avec Doctrine</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/colonnes-de-recherche-perso-dans-le-filter-de-ladmin-generator-avec-doctrine-612</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/colonnes-de-recherche-perso-dans-le-filter-de-ladmin-generator-avec-doctrine-612#comments</comments>
		<pubDate>Wed, 22 Apr 2009 18:17:34 +0000</pubDate>
		<dc:creator>Nikaw</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Admingenerator 1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[admingenerator]]></category>
		<category><![CDATA[custom column]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[filter]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=612</guid>
		<description><![CDATA[-Comment faire pour filtrer l'affichage dans l'admin generator lorsqu'on a à faire à un champs qui n'est pas dans la table considérée ?

Un exemple ici : j'ai des utilisateurs, avec la table User, mais j'ai aussi une table sfGuardUser.

Ma table User contient les infos globales de mes utilisateurs, alors que la table sfGuardUser contient les informations d'identification et permet également de récupérer les infos sur les permissions, les groupes, etc.

Voilà le problème : j'ai dans le listing de mes utilisateurs ajouté la colonne "Administrateur ?", indiquant si l'utilisateur est admin ou non (vous l'aurez compris...), pour cela il m'a suffit de rajouter la méthode getIsAdmin() dans ma classe User.class.php (lib/model/doctrine/User.class.php), et le champs is_admin dans le generator.yml de mon module user dans le backend (apps/backend/modules/user/config/generator.yml). (<a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/12">cf jobeet n°12</a>)]]></description>
			<content:encoded><![CDATA[<p>Comment faire pour filtrer l&#8217;affichage dans l&#8217;admin generator lorsqu&#8217;on a à faire à un champs qui n&#8217;est pas dans la table considérée ?</p>
<p>Un exemple ici : j&#8217;ai des utilisateurs, avec la table User, mais j&#8217;ai aussi une table sfGuardUser.</p>
<p>Ma table User contient les infos globales de mes utilisateurs, alors que la table sfGuardUser contient les informations d&#8217;identification et permet également de récupérer les infos sur les permissions, les groupes, etc.</p>
<p>Voilà le problème : j&#8217;ai dans le listing de mes utilisateurs ajouté la colonne &laquo;&nbsp;Administrateur ?&nbsp;&raquo;, indiquant si l&#8217;utilisateur est admin ou non (vous l&#8217;aurez compris&#8230;), pour cela il m&#8217;a suffit de rajouter la méthode getIsAdmin() dans ma classe User.class.php (lib/model/doctrine/User.class.php), et le champs is_admin dans le generator.yml de mon module user dans le backend (apps/backend/modules/user/config/generator.yml). (<a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/12">cf jobeet n°12</a>)<span id="more-612"></span></p>
<p>Pour le filter le problème est un tout petit peu plus complexe : il n&#8217;utilise pas la classe pour filtrer l&#8217;affichage, et n&#8217;utilisera donc pas la méthode getIsAdmin().</p>
<p>Pourquoi ?</p>
<p>Par ce qu&#8217;il ne fait que générer une requete Doctrine_Query executée dans l&#8217;action.</p>
<p>Il y&#8217;aura donc ici 3 choses à faire :</p>
<ol>
<li>ajouter le champs is_admin dans le formulaire du filter</li>
<li>surcharger la méthode getFields() (sert à récupérer les valeurs du formulaire)</li>
<li>ajouter la méthode qui modifie la requête</li>
</ol>
<p><strong>1) Ajout du champs is_admin</strong> (lib/form/filter/doctrine/UserFormFilter.class.php)<br />
Le formulaire du filtre n&#8217;est rien de mieux qu&#8217;un formulaire sfFormFilter, on a donc déjà vu comment ça marche</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('p612code33'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p61233"><td class="code" id="p612code33"><pre class="php" style="font-family:monospace;">    <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;">'is_admin'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorBoolean<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</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;">$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_admin'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormSelect<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'oui'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'non'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Pensez aussi à créer le label correspondant.</p>
<p>2)   <strong>Surcharge de getFields()</strong> (lib/form/filter/doctrine/UserFormFilter.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('p612code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p61234"><td class="code" id="p612code34"><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> getFields<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: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'is_admin'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'IsAdmin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">getFields</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></pre></td></tr></table></div>

<p><strong>3) Ajout de la méthode de modification de la requête :</strong></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('p612code35'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p61235"><td class="code" id="p612code35"><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> addIsAdminColumnQuery<span style="color: #009900;">&#40;</span>Doctrine_Query <span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</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;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//je cherche à trouver les admins</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRootAlias</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innerJoin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.sfGuardUser u'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">innerJoin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'u.sfGuardUserPermission up'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">innerJoin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'up.sfGuardPermission p'</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.name = ?'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//si je cherche les non admins</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRootAlias</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innerJoin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.sfGuardUser u'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">innerJoin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'u.sfGuardUserPermission up'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">innerJoin</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'up.sfGuardPermission p'</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.name = ?'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'member'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$q</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Essayons de voir le plan général :</p>
<p>- la méthode à ajouter doit s&#8217;appeler add*nom de la colonne*ColumnQuery<br />
- elle prend en paramètres :</p>
<p>- la requête déjà défini par les autres champs du filtre, si aucun champs n&#8217;est renseigné elle correspond à la<br />
requête récupérant tous les objets en question (ici les utilisateurs)</p>
<p>- le nom du champs en question</p>
<p>- la valeur entrée dans le formulaire filter.</p>
<p>A vous de modifier ensuite la requête passée en paramètre pour filtrer vos résultats.<br />
Et voilà !!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/colonnes-de-recherche-perso-dans-le-filter-de-ladmin-generator-avec-doctrine-612/feed</wfw:commentRss>
		<slash:comments>1</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 13:14:33 +0000</pubDate>
		<dc:creator>olivier</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.]]></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 width="100%" ><tr id="p50836"><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="p508code36"><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('p508code37'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50837"><td class="code" id="p508code37"><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('p508code38'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50838"><td class="code" id="p508code38"><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('p508code39'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50839"><td class="code" id="p508code39"><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('p508code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50840"><td class="code" id="p508code40"><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('p508code41'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50841"><td class="code" id="p508code41"><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('p508code42'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50842"><td class="code" id="p508code42"><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('p508code43'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50843"><td class="code" id="p508code43"><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('p508code44'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50844"><td class="code" id="p508code44"><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('p508code45'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50845"><td class="code" id="p508code45"><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('p508code46'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50846"><td class="code" id="p508code46"><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('p508code47'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50847"><td class="code" id="p508code47"><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('p508code48'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50848"><td class="code" id="p508code48"><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('p508code49'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50849"><td class="code" id="p508code49"><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('p508code50'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50850"><td class="code" id="p508code50"><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('p508code51'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50851"><td class="code" id="p508code51"><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('p508code52'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50852"><td class="code" id="p508code52"><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('p508code53'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50853"><td class="code" id="p508code53"><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: #990000;">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: #990000;">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: #990000;">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: #990000;">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: #990000;">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('p508code54'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50854"><td class="code" id="p508code54"><pre class="sql" style="font-family:monospace;">&nbsp;
1<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;
2<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;
3<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('p508code55'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50855"><td class="code" id="p508code55"><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('p508code56'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p50856"><td class="code" id="p508code56"><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>5</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 donne : Intégrer Tiny MCE Télécharger et copier : http://tinymce.moxiecode.com/download.php dans : /web/js/tinyMCE Modifier ce [...]]]></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('p197code61'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19761"><td class="code" id="p197code61"><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('p197code62'); return false;">View Code</a> SF</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19762"><td class="code" id="p197code62"><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('p197code63'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19763"><td class="code" id="p197code63"><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>
  protected <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> <span style="color: #990000;">array</span><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> <span style="color: #990000;">array</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;">$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: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><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> <span style="color: #990000;">array</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;">$attributes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><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('p197code64'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19764"><td class="code" id="p197code64"><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>
      <span style="color: #990000;">array</span><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>
      <span style="color: #990000;">array</span><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>10</slash:comments>
		</item>
		<item>
		<title>Gestion de la paternité (Symfony 1.2, Doctrine)</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/nested-set-doctrine-135</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/nested-set-doctrine-135#comments</comments>
		<pubDate>Mon, 23 Feb 2009 23:53:01 +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[gestion]]></category>
		<category><![CDATA[intervallaire]]></category>
		<category><![CDATA[intervalle]]></category>
		<category><![CDATA[nestedset]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/sfblog/?p=135</guid>
		<description><![CDATA[La gestion d&#8217;arbres en SQL se fait traditionnellement par une auto-jointure, avec le champ classique parent_id. Cette méthode est cependant très coûteuse quand il s&#8217;agit de faire des recherches dans cet arbre car il faut alors utiliser la récursivité. Une autre méthode beaucoup plus puissante existe : la gestion intervallaire. Vous pouvez trouver une explication [...]]]></description>
			<content:encoded><![CDATA[<p>La gestion d&#8217;arbres en SQL se fait traditionnellement par une auto-jointure, avec le champ classique parent_id. Cette méthode est cependant très coûteuse quand il s&#8217;agit de faire des recherches dans cet arbre car il faut alors utiliser la récursivité.</p>
<p>Une autre méthode beaucoup plus puissante existe : la gestion intervallaire. Vous pouvez trouver une explication détaillée de cette méthode ici :<br />
<a href="http://sqlpro.developpez.com/cours/arborescence/">http://sqlpro.developpez.com/cours/arborescence/</a>.</p>
<p>Nous allons voir dans cet article comment implémenter celle-ci dans un projet symfony 1.2 avec doctrine.</p>
<p><span id="more-135"></span></p>
<h2>Pré-requis</h2>
<ul>
<li>Un backend symfony 1.2, doctrine</li>
<li>Comment créer un projet symfony 1.2 Doctrine :<br />
<a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/03">http://www.symfony-project.org/jobeet/1_2/Doctrine/en/03</a></li>
<li>Comment créer une application backend :<br />
<a>http://www.symfony-project.org/jobeet/1_2/Doctrine/en/12</a></li>
<li>Tout ce post est basé sur le travail des gens de ce lien (en anglais) :<br />
<a href="http://redotheoffice.com/">http://redotheoffice.com/</a></li>
</ul>
<h2>Schéma</h2>
<blockquote><p>/config/doctrine/schema.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('p135code83'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13583"><td class="code" id="p135code83"><pre class="yaml" style="font-family:monospace;">Tree:
  actAs:
    NestedSet:
      hasManyRoots: true
      rootColumnName: root_id
  columns:
    name:
      type: string(255)</pre></td></tr></table></div>

<h2>Module</h2>
<p>Créez le module :</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('p135code84'); return false;">View Code</a> SF</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13584"><td class="code" id="p135code84"><pre class="sf" style="font-family:monospace;"> symfony doctrine:generate-admin backend Tree --module=tree</pre></td></tr></table></div>

<h2>Formulaire</h2>
<p>Modifiez la classe de formulaire :</p>
<blockquote><p>/lib/form/doctrine/TreeForm.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('p135code85'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13585"><td class="code" id="p135code85"><pre class="php" style="font-family:monospace;">widgetSchema<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'parent_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormDoctrineChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tree'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'add_empty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'~ (object is at root level)'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'order_by'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'root_id, lft'</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: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'getIndentedName'</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;">'parent_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDoctrineChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tree'</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;">setDefault</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_id'</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;">-&gt;</span><span style="color: #004000;">getParentId</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Child of'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updateParentIdColumn<span style="color: #009900;">&#40;</span><span style="color: #000088;">$parentId</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;">parentId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$parentId</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// further action is handled in the save() method</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  protected <span style="color: #000000; font-weight: bold;">function</span> doSave<span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">doSave</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$node</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;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</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;">parentId</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;">-&gt;</span><span style="color: #004000;">getParentId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValidNode</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: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentId</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//save as a root</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValidNode</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;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">makeRoot</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">object</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</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;">object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</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;">object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTree</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createRoot</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//calls $this-&gt;object-&gt;save internally</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//form validation ensures an existing ID for $this-&gt;parentId</span>
        <span style="color: #000088;">$parent</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;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parentId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValidNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'move'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'insert'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'AsFirstChildOf'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//calls $this-&gt;object-&gt;save internally</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>

<h2>Modèle</h2>
<p>Modifiez la classe du modèle :</p>
<blockquote><p>/lib/model/doctrine/Tree.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('p135code86'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13586"><td class="code" id="p135code86"><pre class="php" style="font-family:monospace;">getIndentedName<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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getParentId<span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValidNode</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;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isRoot</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;">return</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$parent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$parent</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getIndentedName<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: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'- '</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'level'</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: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Actions</h2>
<p>Modifier la classe action du module :</p>
<blockquote><p>/apps/backend/modules/tree/actions</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('p135code87'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13587"><td class="code" id="p135code87"><pre class="php" style="font-family:monospace;">addOrderBy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'root_id, lft'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeBatch<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: #0000ff;">&quot;batchOrder&quot;</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;">'batch_action'</span><span style="color: #009900;">&#41;</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;">executeBatchOrder</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    parent<span style="color: #339933;">::</span><span style="color: #004000;">executeBatch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeBatchOrder<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;">$newparent</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;">'newparent'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//manually validate newparent parameter</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//make list of all ids</span>
    <span style="color: #000088;">$ids</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newparent</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$ids</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$ids</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ids</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//validate if all id's exist</span>
    <span style="color: #000088;">$validator</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDoctrineChoiceMany<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Tree'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    try
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// validate ids</span>
      <span style="color: #000088;">$ids</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;">$ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// the id's validate, now update the tree</span>
      <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$flash</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newparent</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$parentId</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: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parentId</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$node</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;">'Tree'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$parent</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;">'Tree'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parentId</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: #339933;">!</span><span style="color: #000088;">$parent</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isDescendantOfOrEqualTo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">moveAsFirstChildOf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$node</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;">$count</span><span style="color: #339933;">++;</span>
&nbsp;
            <span style="color: #000088;">$flash</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
Moved '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' under '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$parent</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'.&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notice'</span><span style="color: #339933;">,</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Tree order updated, moved <span style="color: #009933; font-weight: bold;">%s</span> item<span style="color: #009933; font-weight: bold;">%s</span>:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$flash</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">'s'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;You must at least move one item to update the tree order&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</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: #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;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Cannot update the tree order, maybe some item are deleted, try again'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <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;">'@tree'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeDelete<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;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">checkCSRFProtection</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;">dispatcher</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;">'admin.delete_object'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'object'</span> <span style="color: #339933;">=&gt;</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: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <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;">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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValidNode</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;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$object</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>
    <span style="color: #009900;">&#125;</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;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notice'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The item was deleted successfully.'</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;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@tree'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeListNew<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;">executeNew</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</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;">-&gt;</span><span style="color: #004000;">setDefault</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_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;">'id'</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;">setTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  protected <span style="color: #000000; font-weight: bold;">function</span> processForm<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #339933;">,</span> sfForm <span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$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;">$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: #339933;">,</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: #000088;">$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>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$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;">$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;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notice'</span><span style="color: #339933;">,</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;">isNew</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'The item was created successfully.'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'The item was updated successfully.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000088;">$tree</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dispatcher</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;">'admin.save_object'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'object'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$tree</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;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_save_and_add'</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notice'</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;">getFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notice'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' You can add another one below.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//$this-&gt;redirect('@tree_new');</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//$this-&gt;redirect('@tree_edit?id='.$tree['id']);</span>
      <span style="color: #009900;">&#125;</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;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFlash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'The item has not been saved due to some errors.'</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>Generator</h2>
<p>Modifiez le fichier :</p>
<blockquote><p>/apps/backend/modules/tree/config/generator.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('p135code88'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13588"><td class="code" id="p135code88"><pre class="yml" style="font-family:monospace;">generator:
  class: sfDoctrineGenerator
  param:
    model_class:           Tree
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          tree_tree
    with_doctrine_route:     1
&nbsp;
    config:
      actions: ~
      fields:  ~
      list:
        title:   Gestions des catégories
        max_per_page: 999999
        batch_actions:
          order:
            label: Update tree order
          _delete: ~
        object_actions:
          new:
            label: Add Child
          _edit:    ~
          _delete:  ~
        actions:
          _new:
            label: Add Root
      filter:  ~
      form:    ~
      edit:
        title: Editing Categorie &quot;%%name%%&quot;
      new:     ~</pre></td></tr></table></div>

<h2>Templates</h2>
<ul> Créez les fichiers suivant :</p>
<li> <strong>_list.php</strong><br />
<blockquote><p>/apps/backend/modules/tree/templates_list.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('p135code89'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13589"><td class="code" id="p135code89"><pre class="php" style="font-family:monospace;"><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;sf_admin_list&quot;</span><span style="color: #339933;">&gt;</span>
  getNbResults<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>table id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;main_list&quot;</span> border<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> cellspacing<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>thead<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>th id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_list_batch_actions&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_list_batch_checkbox&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkAll();&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>th<span style="color: #339933;">&gt;</span>
<span style="color: #000088;">$sort</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>th id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_list_th_actions&quot;</span><span style="color: #339933;">&gt;&lt;/</span>th<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>thead<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tfoot<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>th colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;8&quot;</span><span style="color: #339933;">&gt;</span>
            haveToPaginate<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: #000088;">$pager</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
             <span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNbResults</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;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNbResults</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sf_admin'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            haveToPaginate<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: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%%nb_pages%%'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pager</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastPage</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: #0000ff;">'sf_admin'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tfoot<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
        getResults<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$tree</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000088;">$odd</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fmod</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'odd'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'even'</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>tr id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;node-&lt;?php echo <span style="color: #006699; font-weight: bold;">$tree</span>['id'] ?&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_row &lt;?php echo <span style="color: #006699; font-weight: bold;">$odd</span> ?&gt;&lt;?php // insert hierarchical info <span style="color: #006699; font-weight: bold;">$node</span> = <span style="color: #006699; font-weight: bold;">$tree-&gt;getNode</span>(); if (<span style="color: #006699; font-weight: bold;">$node-&gt;isValidNode</span>() &amp;&amp; <span style="color: #006699; font-weight: bold;">$node-&gt;hasParent</span>()) { echo&quot;</span><span style="color: #339933;">&gt;</span>getParent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #009900;">&#125;</span>
          <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #0000ff;">&quot;&gt;
             <span style="color: #006699; font-weight: bold;">$tree</span>, 'helper' =&gt; <span style="color: #006699; font-weight: bold;">$helper</span>)) ?&gt;
             <span style="color: #006699; font-weight: bold;">$tree</span>)) ?&gt;
             <span style="color: #006699; font-weight: bold;">$tree</span>, 'helper' =&gt; <span style="color: #006699; font-weight: bold;">$helper</span>)) ?&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;script type=&quot;</span>text<span style="color: #339933;">/</span>javascript<span style="color: #0000ff;">&quot;&gt;&lt;!--mce:0--&gt;&lt;/script&gt;</span></pre></td></tr></table></div>

</li>
<li><strong>_list_footer.php</strong><br />
<blockquote><p>/apps/backend/modules/tree/templates_list_footer.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('p135code90'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13590"><td class="code" id="p135code90"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>em<span style="color: #339933;">&gt;</span>After changing the order of the tree<span style="color: #339933;">,</span> the <span style="color: #000000; font-weight: bold;">new</span> order should be saved<span style="color: #339933;">.</span> This is currently implemented
<span style="color: #b1b100;">as</span> a batch action<span style="color: #339933;">,</span> so please choose <span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;</span>Update tree order<span style="color: #339933;">&lt;/</span>strong<span style="color: #339933;">&gt;</span> from the <span style="color: #0000ff;">'Choose an action'</span> dropdown
and click on <span style="color: #0000ff;">'Go'</span> to save the <span style="color: #000000; font-weight: bold;">new</span> order<span style="color: #339933;">.&lt;/</span>em<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
<li> <strong>_list_td_batch_actions.php</strong><br />
<blockquote><p>/apps/backend/modules/tree/templates_list_td_batch_actions.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('p135code91'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13591"><td class="code" id="p135code91"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sf_admin_batch_checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ids[]&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$tree-&gt;getPrimaryKey</span>() ?&gt;&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;select_node-&lt;?php echo <span style="color: #006699; font-weight: bold;">$tree-&gt;getPrimaryKey</span>() ?&gt;&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;newparent[&lt;?php echo <span style="color: #006699; font-weight: bold;">$tree-&gt;getPrimaryKey</span>() ?&gt;]&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> <span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

</li>
<li> <strong>_list_td_tabular.php</strong><br />
<blockquote><p>/apps/backend/modules/tree/templates/_list_td_tabular.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('p135code92'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13592"><td class="code" id="p135code92"><pre class="php" style="font-family:monospace;">  <span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$tree-&gt;getNode</span>()-&gt;isLeaf() ? 'file' : 'folder' ?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
</ul>
<h2>CSS/JS</h2>
<ul>
<li> <strong>CSS</strong>Créez ce fichier :<br />
<blockquote><p>/web/css/jQuery.treeTable.css</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('p135code93'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13593"><td class="code" id="p135code93"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* jQuery TreeTable Core 2.0 stylesheet
 *
 * This file contains styles that are used to display the tree table. Each tree
 * table is assigned the +treeTable+ class.
 * ========================================================================= */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* jquery.treeTable.collapsible
 * ------------------------------------------------------------------------- */</span>
<span style="color: #6666ff;">.treeTable</span> tr td <span style="color: #6666ff;">.expander</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	zoom<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* IE7 Hack */</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.collapsed</span> td <span style="color: #6666ff;">.expander</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/toggle-expand-dark.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.expanded</span> td <span style="color: #6666ff;">.expander</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/toggle-collapse-dark.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* jquery.treeTable.sortable
 * ------------------------------------------------------------------------- */</span>
<span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.selected</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.accept</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccccff</span> !important<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span> !important<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span> 
&nbsp;
<span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.collapsed</span><span style="color: #6666ff;">.selected</span> td <span style="color: #6666ff;">.expander</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.collapsed</span><span style="color: #6666ff;">.accept</span> td <span style="color: #6666ff;">.expander</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/toggle-expand-light.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.expanded</span><span style="color: #6666ff;">.selected</span> td <span style="color: #6666ff;">.expander</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.treeTable</span> tr<span style="color: #6666ff;">.expanded</span><span style="color: #6666ff;">.accept</span> td <span style="color: #6666ff;">.expander</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/toggle-collapse-light.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.treeTable</span> <span style="color: #6666ff;">.ui-draggable-dragging</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Créez ce fichier :</p>
<blockquote><p>/web/css/main.css</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('p135code94'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13594"><td class="code" id="p135code94"><pre class="css" style="font-family:monospace;">table span <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">.2em</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">.2em</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
table span<span style="color: #6666ff;">.file</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/page_white_text.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
table span<span style="color: #6666ff;">.folder</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../images/folder.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</li>
<li> <strong>Javascript</strong>Créez ce fichier :<br />
<blockquote><p>/web/js/jQuery.treeTable.js</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('p135code95'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13595"><td class="code" id="p135code95"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* jQuery treeTable Plugin 2.2 - http://ludo.cubicphuse.nl/jquery-plugins/treeTable/ */</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: #006600; font-style: italic;">// Helps to make options available to all functions</span>
  <span style="color: #006600; font-style: italic;">// TODO: This gives problems when there are both expandable and non-expandable</span>
  <span style="color: #006600; font-style: italic;">// trees on a page. The options shouldn't be global to all these instances!</span>
  <span style="color: #003366; font-weight: bold;">var</span> options<span style="color: #339933;">;</span>
&nbsp;
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">treeTable</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">treeTable</span>.<span style="color: #660066;">defaults</span><span style="color: #339933;">,</span> opts<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</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: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;treeTable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tbody tr&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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: #006600; font-style: italic;">// Initialize root nodes only whenever possible</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>options.<span style="color: #660066;">expandable</span> <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: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span>.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;child-of-&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          initialize<span style="color: #009900;">&#40;</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: #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>
    <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;
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">treeTable</span>.<span style="color: #660066;">defaults</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    childPrefix<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;child-of-&quot;</span><span style="color: #339933;">,</span>
    expandable<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    indent<span style="color: #339933;">:</span> <span style="color: #CC0000;">19</span><span style="color: #339933;">,</span>
    initialState<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;collapsed&quot;</span><span style="color: #339933;">,</span>
    treeColumn<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Recursively hide all node's children in a tree</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">collapse</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;collapsed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    childrenOf<span style="color: #009900;">&#40;</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: #009900;">&#41;</span>.<span style="color: #660066;">each</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>
      initialize<span style="color: #009900;">&#40;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><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;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;collapsed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;">collapse</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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Recursively show all node's children in a tree</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">expand</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;collapsed&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;expanded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    childrenOf<span style="color: #009900;">&#40;</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: #009900;">&#41;</span>.<span style="color: #660066;">each</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>
      initialize<span style="color: #009900;">&#40;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.expanded.parent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;">expand</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;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Add an entire branch to +destination+</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">appendBranchTo</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>destination<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> node <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: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> parent <span style="color: #339933;">=</span> parentOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> ancestorNames <span style="color: #339933;">=</span> $.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span>ancestorsOf<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>destination<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> a.<span style="color: #660066;">id</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: #006600; font-style: italic;">// Conditions:</span>
    <span style="color: #006600; font-style: italic;">// 1: +node+ should not be inserted in a location in a branch if this would</span>
    <span style="color: #006600; font-style: italic;">//    result in +node+ being an ancestor of itself.</span>
    <span style="color: #006600; font-style: italic;">// 2: +node+ should not have a parent OR the destination should not be the</span>
    <span style="color: #006600; font-style: italic;">//    same as +node+'s current parent (this last condition prevents +node+</span>
    <span style="color: #006600; font-style: italic;">//    from being moved to the same location where it already is).</span>
    <span style="color: #006600; font-style: italic;">// 3: +node+ should not be inserted as a child of +node+ itself.</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">inArray</span><span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #339933;">,</span> ancestorNames<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>parent <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>destination.<span style="color: #660066;">id</span> <span style="color: #339933;">!=</span> parent<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> destination.<span style="color: #660066;">id</span> <span style="color: #339933;">!=</span> node<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      indent<span style="color: #009900;">&#40;</span>node<span style="color: #339933;">,</span> ancestorsOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">*</span> options.<span style="color: #660066;">indent</span> <span style="color: #339933;">*</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Remove indentation</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>parent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> node.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">childPrefix</span> <span style="color: #339933;">+</span> parent<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
      node.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">childPrefix</span> <span style="color: #339933;">+</span> destination.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      move<span style="color: #009900;">&#40;</span>node<span style="color: #339933;">,</span> destination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Recursively move nodes to new location</span>
      indent<span style="color: #009900;">&#40;</span>node<span style="color: #339933;">,</span> ancestorsOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">*</span> options.<span style="color: #660066;">indent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Add reverse() function from JS Arrays</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">reverse</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pushStack</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">reverse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Toggle an entire branch</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">toggleBranch</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;collapsed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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;">expand</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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</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;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;expanded&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">collapse</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: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// === Private functions</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> ancestorsOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> ancestors <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>node <span style="color: #339933;">=</span> parentOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ancestors<span style="color: #009900;">&#91;</span>ancestors.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> node<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> ancestors<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> childrenOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table.treeTable tbody tr.&quot;</span> <span style="color: #339933;">+</span> options.<span style="color: #660066;">childPrefix</span> <span style="color: #339933;">+</span> node<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> indent<span style="color: #009900;">&#40;</span>node<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> cell <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>options.<span style="color: #660066;">treeColumn</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> padding <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>cell.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;padding-left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> value<span style="color: #339933;">;</span>
&nbsp;
    cell.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;padding-left&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">+</span> padding <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    childrenOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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>
      indent<span style="color: #009900;">&#40;</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: #339933;">,</span> value<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;
  <span style="color: #003366; font-weight: bold;">function</span> initialize<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;initialized&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      node.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;initialized&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">var</span> childNodes <span style="color: #339933;">=</span> childrenOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;parent&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> childNodes.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        node.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;parent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;parent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> cell <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>options.<span style="color: #660066;">treeColumn</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> padding <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>cell.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;padding-left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> options.<span style="color: #660066;">indent</span><span style="color: #339933;">;</span>
&nbsp;
        childNodes.<span style="color: #660066;">each</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>options.<span style="color: #660066;">treeColumn</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;padding-left&quot;</span><span style="color: #339933;">,</span> padding <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;px&quot;</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">expandable</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          cell.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          $<span style="color: #009900;">&#40;</span>cell<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</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><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> node.<span style="color: #660066;">toggleBranch</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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #006600; font-style: italic;">// Check for a class set explicitly by the user, otherwise set the default class</span>
          <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;expanded&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;collapsed&quot;</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>
            node.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">initialState</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;collapsed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            node.<span style="color: #660066;">collapse</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: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;expanded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            node.<span style="color: #660066;">expand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> move<span style="color: #009900;">&#40;</span>node<span style="color: #339933;">,</span> destination<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    node.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>destination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    childrenOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">reverse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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> move<span style="color: #009900;">&#40;</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: #339933;">,</span> node<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</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: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> parentOf<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> classNames <span style="color: #339933;">=</span> node<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>key <span style="color: #000066; font-weight: bold;">in</span> classNames<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>classNames<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;child-of-&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> classNames<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">9</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: #339933;">;</span>
<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></pre></td></tr></table></div>

</li>
</ul>
<h2>view.yml</h2>
<p>Modifiez ce fichier :</p>
<blockquote><p>/apps/backend/config/view.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('p135code96'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13596"><td class="code" id="p135code96"><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.treeTable.css]
&nbsp;
  javascripts:
    - http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js
    - http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js
    - jquery.treeTable.js
&nbsp;
  has_layout:     on
  layout:         layout</pre></td></tr></table></div>

<h2>Routing</h2>
<p>Il faut rajouter la règle de routage &laquo;&nbsp;tree&nbsp;&raquo; !!</p>
<blockquote><p>/apps/backend/config/routing.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('p135code97'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13597"><td class="code" id="p135code97"><pre class="yml" style="font-family:monospace;">tree_tree:
  class: sfDoctrineRouteCollection
  options:
    model:               Tree
    module:              tree
    prefix_path:         tree
    column:              id
    with_wildcard_routes: true
tree:
  class: sfDoctrineRouteCollection
  options:
    model:               Tree
    module:              tree
    prefix_path:         tree
    column:              id
    with_wildcard_routes: true
# default rules
homepage:
  url:   /
  param: { module: default, action: index }
&nbsp;
default_index:
  url:   /:module
  param: { action: index }
&nbsp;
default:
  url:   /:module/:action/*</pre></td></tr></table></div>

<h2>Clear Cache</h2>
<p>On vide le cache :</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('p135code98'); return false;">View Code</a> SF</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13598"><td class="code" id="p135code98"><pre class="sf" style="font-family:monospace;">symfony cc</pre></td></tr></table></div>

<h2>Fixtures</h2>
<p>Ajouter ce fichier :</p>
<blockquote><p>/data/fixtures/data.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('p135code99'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13599"><td class="code" id="p135code99"><pre class="yml" style="font-family:monospace;">Tree:
  Tree_1:
    name: Couleurs
    root_id: '1'
    lft: '1'
    rgt: '8'
    level: '0'
  Tree_2:
    name: Bleu
    root_id: '1'
    lft: '6'
    rgt: '7'
    level: '1'
  Tree_3:
    name: Rouge
    root_id: '1'
    lft: '2'
    rgt: '3'
    level: '1'
  Tree_4:
    name: Vert
    root_id: '1'
    lft: '4'
    rgt: '5'
    level: '1'
  Tree_5:
    name: Langages
    root_id: '5'
    lft: '1'
    rgt: '14'
    level: '0'
  Tree_6:
    name: Serveur
    root_id: '5'
    lft: '8'
    rgt: '13'
    level: '1'
  Tree_7:
    name: Client
    root_id: '5'
    lft: '2'
    rgt: '7'
    level: '1'
  Tree_8:
    name: Javascript
    root_id: '5'
    lft: '5'
    rgt: '6'
    level: '2'
  Tree_9:
    name: ActionScript
    root_id: '5'
    lft: '3'
    rgt: '4'
    level: '2'
  Tree_10:
    name: PHP
    root_id: '5'
    lft: '11'
    rgt: '12'
    level: '2'
  Tree_11:
    name: ASP
    root_id: '5'
    lft: '9'
    rgt: '10'
    level: '2'</pre></td></tr></table></div>

<h2>build-all-reload</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('p135code100'); return false;">View Code</a> SF</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p135100"><td class="code" id="p135code100"><pre class="sf" style="font-family:monospace;">symfony doctrine:build-all-reload</pre></td></tr></table></div>

<h2>Les images :</h2>
<p>A copier dans web/images</p>
<table style="border: 1px solid #cccccc; background-color:white;padding: 5" border="0">
<tbody>
<tr>
<td style="border: 1px solid #cccccc; height: 30px; width: 5px; background-color: #cccccc;"><img src="http://img254.imageshack.us/img254/655/pagewhitetext.png" alt="pagewhitetext.png" /></td>
<td>page_white_text.png</td>
<td></td>
</tr>
<tr>
<td style="border: 1px solid #cccccc; height: 30px; width: 5px; background-color: #cccccc;"><img src="http://img254.imageshack.us/img254/2125/folder.png" alt="pagewhitetext.png" /></td>
<td>folder.png</td>
</tr>
<tr>
<td style="border: 1px solid #cccccc; height: 30px; width: 5px; background-color: #cccccc;"><img src="http://img254.imageshack.us/img254/1466/togglecollapsedark.png" alt="toggle_collapse_dark.png" /></td>
<td>toggle_collapse_dark.png</td>
</tr>
<tr>
<td style="border: 1px solid #cccccc; height: 30px; width: 5px; background-color: #cccccc;"><img src="http://img254.imageshack.us/img254/9655/togglecollapselight.png" alt="toggle_collapse_light.png" /></td>
<td>toggle_collapse_light.png</td>
</tr>
<tr>
<td style="border: 1px solid #cccccc; height: 30px; width: 5px; background-color: #cccccc;"><img src="http://img254.imageshack.us/img254/7884/toggleexpanddark.png" alt="toggle_expand_dark.png" /></td>
<td>toggle_expand_dark.png</td>
</tr>
<tr>
<td style="border: 1px solid #cccccc; height: 30px; width: 5px; background-color: #cccccc;"><img src="http://img254.imageshack.us/img254/8070/toggleexpandlight.png" alt="toggle_expand_light.png" /></td>
<td>toggle_expand_light.png</td>
</tr>
</tbody>
</table>
<h2>Aperçu</h2>
<p>Vous devriez avoir ça !</p>
<p><img src="http://img509.imageshack.us/img509/1218/shinynested.jpg" border="0" alt="" /></p>
<hr />Je rajoute un lien pratique: un petit outil que nous  avons fait pour pouvoir générer automatiquement tous les  fichiers, donc plus besoin de suivre le post à la lettre, complétez le formulaire et télécharger vos fichiers créés:<em><br />
<a href="http://www.lexik.fr/nested/index.php" target="_blank">http://www.lexik.fr/nested/index.php</a></em></p>
<p><em><br />
Sources :</em></p>
<ul>
<li> <em><a href="http://sqlpro.developpez.com/cours/arborescence/">http://sqlpro.developpez.com/cours/arborescence/</a> </em></li>
<li> <em><a href="http://www.symfony-project.org/jobeet/">http://www.symfony-project.org/jobeet/</a> </em></li>
<li> <em><a href="http://redotheoffice.com/">http://redotheoffice.com/</a> </em></li>
</ul>
<p><em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/nested-set-doctrine-135/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
