<?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>Amicalement Web - Astuces et Bons plans dans le développement web &#187; astuce</title>
	<atom:link href="http://www.amicalement-web.net/tag/astuce/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.amicalement-web.net</link>
	<description>Astuces et bons plans d&#039;un web developpeur</description>
	<lastBuildDate>Thu, 03 Jun 2010 10:06:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Symfony: Une utilisation du type array de Doctrine</title>
		<link>http://www.amicalement-web.net/symfony-une-utilisation-du-type-array-de-doctrine/2009/11/04/</link>
		<comments>http://www.amicalement-web.net/symfony-une-utilisation-du-type-array-de-doctrine/2009/11/04/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 10:00:47 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=925</guid>
		<description><![CDATA[ Oui, les billets Symfony commençaient à me manquer. Mais difficile de trouver et le temps et la ressource pour en faire. Mais voici une petite astuce illustrée qui permet de trouver une application au type array de Doctrine tout en simplifiant une problématique. Tout ce que j&#8217;aime.

Commençons par rendre à César ce qui est [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/check.png" alt="check" title="check" width="614" height="100" class="alignnone size-full wp-image-927" /> Oui, les billets Symfony commençaient à me manquer. Mais difficile de trouver et le temps et la ressource pour en faire. Mais voici une petite astuce illustrée qui permet de trouver une application au <a  href="http://www.doctrine-project.org/documentation/manual/1_1/en/defining-models#columns:data-types:array">type array de Doctrine</a> tout en simplifiant une problématique. Tout ce que j&#8217;aime.<br />
<span id="more-925"></span><br />
Commençons par rendre à César ce qui est à César, j&#8217;avais dans l&#8217;idée d&#8217;essayer ce type mais les exemples sur la doc ou sur le net n&#8217;était pas légion. En bon fainéant que je suis, j&#8217;ai demandé un peu d&#8217;aide et c&#8217;est mon nouveau voisin de droite, <a  href="http://twitter.com/colinux">Colin</a> qui m&#8217;a soufflé un bout de code où il l&#8217;utilise.</p>
<h3>Problématique</h3>
<p>Il me fallait stocker le résultat d&#8217;une question à choix multiple sans pour autant avoir à manipuler ensuite ses résultats autrement que par simple visualisation. Du coup, je voulais éviter d&#8217;avoir à créer une table pour stocker ces réponses et une table d&#8217;association avec ma table miroir de mon formulaire.</p>
<p>C&#8217;est là où le type array intervient. Rien de compliqué en fait, il ne fait que simplifier un traitement tout bête qui consiste à stocker un tableau php en base après sérialisation. Et qui le désérialise quand on le récupère depuis un enregistrement de la base.<br />
Une chose de moins à faire en fait et c&#8217;est bien là ce qu&#8217;on recherche nous autres développeurs, en faire le moins possible ;)</p>
<h3>La solution codée</h3>
<p>Niveau code, c&#8217;est très simple. On défini notre champ dans notre <code>schema.yml</code> comme n&#8217;importe quel autre champ</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">meschoix: { type: array(1000) }</pre></div></div>

<p>Qui donnera un champ text en mysql.</p>
<p>Ensuite, il suffit de modifier le formulaire obtenu pour transformer notre champ en liste de checkbox de manière très classique:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meschoix'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormChoice<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;">'0'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Choix1'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Choix2'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Choix3'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'3'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Choix4'</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'multiple'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'expanded'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Et puis c&#8217;est tout! Maintenant, lors de l&#8217;enregistrement, Doctrine va sérialiser le résultat de votre sélection et le stocker en base. Et quand vous peuplerez votre formulaire avec des données en base, il le désérialisera et donnera les bonnes valeurs à notre liste de checkbox.</p>
<p>Bien sûr, ca nous oblige à ne pas changer l&#8217;ordre des questions et les rend difficilement modifiables. Mais c&#8217;est une décision qui doit être prise en connaissance de cette limitation.</p>
<p><small>Crédit photo: http://www.flickr.com/photos/40491122@N03/3738306829/</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/symfony-une-utilisation-du-type-array-de-doctrine/2009/11/04/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Doctrine: quelques petits secrets</title>
		<link>http://www.amicalement-web.net/doctrine-quelques-petits-secrets/2009/08/26/</link>
		<comments>http://www.amicalement-web.net/doctrine-quelques-petits-secrets/2009/08/26/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 09:00:38 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=582</guid>
		<description><![CDATA[ Oui, je commence à parler de Doctrine de plus en plus vu que je commence à l&#8217;utiliser à grande échelle au boulot. Et il y a un détail où j&#8217;ai encore du mal, c&#8217;est l&#8217;opacité de cet ORM comparé à son prédécesseur dans Symfony, Propel.
On se rappelle tous (enfin je parle au passé, mais [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/doctrine-secret.png" alt="doctrine-secret" title="doctrine-secret" width="614" height="100" class="alignnone size-full wp-image-640" /> Oui, je <a  href="/doctrine-et-son-behavior-geographical/2009/08/05/">commence à parler de Doctrine</a> de plus en plus vu que je commence à l&#8217;utiliser à grande échelle au boulot. Et il y a un détail où j&#8217;ai encore du mal, c&#8217;est l&#8217;opacité de cet ORM comparé à son prédécesseur dans Symfony, Propel.</p>
<p>On se rappelle tous (enfin je parle au passé, mais Propel n&#8217;est pas mort hein :p) qu&#8217;on avait tout à disposition dans le BasePeer de notre modèle, les accesseurs, les modificateurs et quasi toutes les méthodes dont on pouvait avoir besoin. Avec Doctrine, la donne a changé, tant cet ORM est codé différemment.</p>
<p>On se retrouve du coup un peu perdu parfois, sans trop savoir ce qu&#8217;on peut utiliser. Et là, il faut bien sûr jeter un œil à l&#8217;<a href="http://www.doctrine-project.org/documentation/api/1_1 ">API Doctrine</a>. Mais on le sait tous, on a pas toujours le temps! Du coup, au travers de mes recherches, j&#8217;ai trouvé quelques petites méthodes que j&#8217;utilise régulièrement et dont je vais vous parler.<br />
<span id="more-582"></span></p>
<h3>Le modèle d&#8217;exemple</h3>
<p>Afin d&#8217;illustrer au mieux les différentes fonctions, je vais prendre en exemple un modèle basique, une liste de lien:</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">MyLink:
  columns:
    name: { type: string(100), notnull: true }
    link: { type: string(255), notnull: true }
    description: { type: string(4000) }</pre></div></div>

<h3>Un save qui retourne un booléen</h3>
<p>Parfois, lors de petites modifications, on a pas toujours le courage de faire un try/catch sur notre transaction. TrySave répond à cette problématique, en incluant directement le try catch sur le save et en retournant un booléen, true si l&#8217;enregistrement a bien été commité, false si une exception a été levée. Bien pratique!</p>
<ul>
<li> <a  href="http://www.doctrine-project.org/Doctrine_Record/1_1#method_trysave">Documentation trySave</a></li>
<li> Exemple:

<div class="wp_syntax"><div class="code"><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> saveMyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Amicalement-web'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.amicalement-web.net'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">trySave</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Retournera true si la sauvegarde a été effectuée, false sinon</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
</ul>
<h3>Le nom de la clé primaire</h3>
<p>Oui des fois, quand on veut généraliser une méthode, on a besoin du nom de la clé primaire de notre model. (Dans le cas d&#8217;un unset en vue d&#8217;un embedForm par exemple).</p>
<ul>
<li><a  href="http://www.doctrine-project.org/Doctrine_Table/1_1#method_getidentifier">Documentation getIdentifier</a></li>
<li> Exemple:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</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;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ul>
<h3>Exporter votre modèle en différents formats</h3>
<p>Que se soit pour générer des XML destinés à une application tiers, ou du json pour votre module javascript, on a souvent besoin de nos modèles dans un format d&#8217;échange. Et bien Doctrine intègre cette fonctionnalité de base, en permettant des export en tableau php, xml, yml et json.</p>
<ul>
<li><a  href="http://www.doctrine-project.org/Doctrine_Record/1_1#method_exportto">Documentation exportTo</a></li>
<li>Exemple

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Symfony Project'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.symfony-project.org'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</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: #b1b100;">echo</span> <span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exportTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Attention par défaut exporte aussi les relations de l'objets. Il faut mettre à false, le 2e argument si on veut conserver seulement notre objet en question</span></pre></div></div>

</li>
<li>
Rendu:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Symfony Project<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.symfony-project.org<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/data<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
</ul>
<h3>Importer votre modèle en différents formats</h3>
<p>Et oui parce que Doctrine fait les choses biens, la réciproque existe aussi et est toute aussi utile. Vous pouvez ainsi hydrater  un objet à partir d&#8217;un xml, json, ou yml grâce à la méthode importFrom</p>
<ul>
<li><a  href="http://www.doctrine-project.org/Doctrine_Record/1_1#method_importfrom">Documentation importFrom</a></li>
<li>Exemple:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'{&quot;id&quot;:&quot;5&quot;,&quot;name&quot;:&quot;Doctrine Project&quot;,&quot;url&quot;:&quot;http:\/\/www.doctrine-project.org&quot;,&quot;description&quot;:&quot;Orm PHP&quot;}'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">importFrom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'json'</span><span style="color: #339933;">,</span><span style="color: #000088;">$json</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$link</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Affiche &quot;Doctrine Project&quot;</span></pre></div></div>

</li>
</ul>
<p>Pour ce qui est d&#8217;hydrater à partir d&#8217;un tableau php, il y a 2 méthodes pour ça: fromArray et hydrate. Leurs différences, c&#8217;est la façon de faire. La première utilise les modificateurs de notre modèle (permettant ainsi de passer par des modifications qu&#8217;on aurait pu apporter à ces méthodes &laquo;&nbsp;set&nbsp;&raquo;) alors que la seconde remplie directement les attributs de notre modèle.</p>
<ul>
<li><a  href="http://www.doctrine-project.org/Doctrine_Record/1_1#method_fromarray">Documentation fromArray</a></li>
<li><a  href="http://www.doctrine-project.org/Doctrine_Record/1_1#method_hydrate">Documentation hydrate</a></li>
<li>
Exemple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// On surcharge le modificateur de la propriété $url pour rajouter 'http://' devant</span>
<span style="color: #000000; font-weight: bold;">class</span> MyLink <span style="color: #000000; font-weight: bold;">extends</span> BaseMyLink
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUrl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    parent<span style="color: #339933;">::</span>_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</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></div></div>

<p>Puis maintenant nos 2 appels:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Amicalement Web'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'www.amicalement-web.net'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link1</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fromArray</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'link1='</span><span style="color: #339933;">.</span><span style="color: #000088;">$link1</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Affiche http://www.amicalement-web.net</span>
&nbsp;
<span style="color: #000088;">$link2</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$link2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hydrate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'link2='</span><span style="color: #339933;">.</span><span style="color: #000088;">$link2</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Affiche www.amicalement-web.net</span></pre></div></div>

</li>
</ul>
<h3>Post/Pre methodes</h3>
<p>Comme je l&#8217;avais utilisé dans l&#8217;exemple du behavior Geographical, Doctrine met à disposition toute une série de méthodes en post et pré traitement de nombreuses fonctionnalités comme</p>
<ul>
<li>Sérialisation</li>
<li>Désérialisation</li>
<li>Sauvegarde</li>
<li>Suppression</li>
<li>Mise à jour</li>
<li>Insertion</li>
<li>Validation</li>
<li>Hydratation</li>
</ul>
<p><a  href="http://www.doctrine-project.org/Doctrine_Record/1_2#method_postdelete">Leur documentation</a> à la suite les unes des autre.</p>
<h3>Libérer de la mémoire</h3>
<p>La performance, sans être un axe principal a mon goût, doit rester dans la tête de chacun. Pour ça, Doctrine propose une méthode pour effacer un objet ainsi que toutes ses références de la mémoire de l&#8217;ORM. A utiliser principalement dans des boucles quand on veut juste faire un traitement sur un ensemble d&#8217;objets dont on ne voudra pas se resservir ensuite.</p>
<ul>
<li><a  href="http://www.doctrine-project.org/Doctrine_Record/1_1#method_free">Documentation free</a></li>
<li>Exemple:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Exemple tiré de la documentation doctrine</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$object</span> <span style="color: #339933;">=</span> createBigObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">free</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// true pour libérer même les relations</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
</ul>
<h3>Hydrater plus efficacement</h3>
<p>Et oui, on le crie pas sur tous les toits, mais on est pas obligé de récupérer des objets complets quand on fait une requête avec doctrine même si c&#8217;est le comportement par défaut.<br />
Quand on veut simplement faire de l&#8217;affichage, parfois seules les données nous intéresse et donc dans un gain de mémoire, on peut changer le mode d&#8217;hydratation:</p>
<ul>
<li>Doctrine::HYDRATE_RECORD</li>
<li>Doctrine::HYDRATE_ARRAY</li>
<li>Doctrine::HYDRATE_NONE</li>
<li>Exemple:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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;">'MyLink'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Comportement par défaut, retourne un tableau d'objet</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</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>Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">HYDRATE_RECORD</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Retourne un tableau associatif où les clés sont les noms des champs</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</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>Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">HYDRATE_ARRAY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Retourne un simple tableau où les champs sont dans l'ordre qu'ils ont été appelés</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</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>Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">HYDRATE_NONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ul>
<p>Cela reste le fruit de mes tests et études, si vous avez des remarques ou des corrections n&#8217;hésitez pas!</p>
<p>Et vous, vous avez quelque chose à partager sur les méandres de Doctrine?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/doctrine-quelques-petits-secrets/2009/08/26/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Symfony: Personnaliser le nom du fichier lors d&#8217;un upload avec sfWidgetFormInputFileEditable</title>
		<link>http://www.amicalement-web.net/symfony-personnaliser-le-nom-du-fichier-lors-dun-upload-avec-sfwidgetforminputfileeditable/2009/07/29/</link>
		<comments>http://www.amicalement-web.net/symfony-personnaliser-le-nom-du-fichier-lors-dun-upload-avec-sfwidgetforminputfileeditable/2009/07/29/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 09:00:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=477</guid>
		<description><![CDATA[ On emploie tous je pense, assez couramment maintenant, le widget sfWidgetFormInputFileEditable qui permet de rajouter quelques fonctionnalités à un widget d&#8217;upload classique, en l&#8217;occurrence visualisation et suppression. Le souci que j&#8217;ai rencontré récemment, c&#8217;est par contre la personnalisation du nom du fichier ainsi généré.
En effet, par défaut celui-ci est une empreinte sha1 généré aléatoirement, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/system-software-update.png" alt="system-software-update" title="system-software-update" width="48" height="48" class="alignleft size-full wp-image-40" /> On emploie tous je pense, assez couramment maintenant, le widget <a  href="http://www.symfony-project.org/api/1_2/sfWidgetFormInputFileEditable" class="extern">sfWidgetFormInputFileEditable</a> qui permet de rajouter quelques fonctionnalités à un widget d&#8217;upload classique, en l&#8217;occurrence visualisation et suppression. Le souci que j&#8217;ai rencontré récemment, c&#8217;est par contre la personnalisation du nom du fichier ainsi généré.</p>
<p>En effet, par défaut celui-ci est une empreinte sha1 généré aléatoirement, ce qui convient pour la majeure partie des cas, mais parfois ne suffit pas. Mais là encore Symfony étonne par le mécanisme mis en place pour contourner cette problématique, encore faut-il le savoir malheureusement.<br />
<span id="more-477"></span></p>
<p>Nous allons prendre un cas classique, une class Medias avec un champ path qui stockera le nom du fichier ainsi uploadé:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MediasForm <span style="color: #000000; font-weight: bold;">extends</span> BaseMediasForm
<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;">'path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputFileEditable<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'file_src'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/uploads/medias/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'is_image'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'edit_mode'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$this</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: #339933;">,</span>
      <span style="color: #0000ff;">'with_delete'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorFile<span style="color: #009900;">&#40;</span><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: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
    	<span style="color: #0000ff;">'path'</span> <span style="color: #339933;">=&gt;</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_upload_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/medias'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'mime_types'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'web_images'</span>
    <span style="color: #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;">'path_delete'</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Maintenant, si on veut avoir la main sur le nom du fichier généré, il suffit tout simplement dans la class Medias de rajouter la méthode suivante:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Ou Path est le nom du champ ciblé lors de l'upload</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> generatePathFilename<span style="color: #009900;">&#40;</span>sfValidatedFile <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// On a maintenant accès à notre fichier, on peut donc lui donner un nom basé sur son id ou son slug ou tout autre chose.</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getExtension</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOriginalExtension</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></div></div>

<p>Tout simplement! C&#8217;est ce genre de détails qui me font apprécier la constante découverte de ce framework ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/symfony-personnaliser-le-nom-du-fichier-lors-dun-upload-avec-sfwidgetforminputfileeditable/2009/07/29/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Personnaliser le code HTML d&#8217;un widget symfony</title>
		<link>http://www.amicalement-web.net/personnaliser-le-code-html-dun-widget-symfony/2009/06/02/</link>
		<comments>http://www.amicalement-web.net/personnaliser-le-code-html-dun-widget-symfony/2009/06/02/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 11:55:49 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[formatter]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=303</guid>
		<description><![CDATA[ Comme dit le proverbe, billet du mardi, billet symfony&#8230; Bon on va dire que c&#8217;est un nouveau proverbe mais pour le coup, on va continuer cet adage avec au programme aujourd&#8217;hui les possibilités offertes par symfony pour modifier le code HTML construit par ses fameux widgets de son système de formulaire.
Plus mon nombre de [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/system-software-update.png" alt="system-software-update" title="system-software-update" width="48" height="48" class="alignleft size-full wp-image-40" /> Comme dit le proverbe, billet du mardi, billet symfony&#8230; Bon on va dire que c&#8217;est un nouveau proverbe mais pour le coup, on va continuer cet adage avec au programme aujourd&#8217;hui les possibilités offertes par symfony pour modifier le code HTML construit par ses fameux widgets de <a  href="http://www.symfony-project.org/forms/1_2/en/" class="extern">son système de formulaire</a>.</p>
<p>Plus mon nombre de projets défile sous Symfony et plus j&#8217;essaye d&#8217;éviter de faire des choses hors framework, mais plutôt de voir comment on pourrait le régler via le framework. Avant, quand un problème se présentait, j&#8217;optais souvent pour une solution alternative quitte à mettre de côté pour une petite fonction la philosophie Symfony. Mais voilà, je l&#8217;aime moi, cette philosophie et au fur et à mesure, j&#8217;ai décidé de mettre de plus en plus les mains dans la cambouis et les yeux dans le code source, pour résoudre mes problèmes.<br />
<span id="more-303"></span><br />
Récemment, j&#8217;étais sur un petit système de sondage très basique qui se présentait donc sous cette forme grâce au complément sfWidgetFormChoice et sfWidgetFormSelectCheckbox:<br />
<img src="http://www.amicalement-web.net/wp-content/uploads/image-49.png" alt="image-49" title="image-49" width="337" height="155" class="alignnone size-full wp-image-304" /></p>
<p>Grâce à un code du genre:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'reponses'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'multiple'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      	<span style="color: #0000ff;">'expanded'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$reponses</span>
      <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>qui me produisait quelque chose comme ça:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;ul class=&quot;radio_list&quot;&gt;
&lt;li&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_7&quot; value=&quot;7&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_7&quot;&gt;Oula&lt;/label&gt;&lt;/li&gt;
&lt;li&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_8&quot; value=&quot;8&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_8&quot;&gt;Ola&lt;/label&gt;&lt;/li&gt;
&lt;li&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_9&quot; value=&quot;9&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_9&quot;&gt;Woot&lt;/label&gt;&lt;/li&gt;
&lt;li&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_10&quot; value=&quot;10&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_10&quot;&gt;Wagli&lt;/label&gt;&lt;/li&gt;
&lt;li&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_11&quot; value=&quot;11&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_11&quot;&gt;Plop&lt;/label&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></div></div>

<p>Ca fonctionne parfaitement, mais voilà à l&#8217;intégration, j&#8217;avais 2 checkbox par ligne&#8230; Et pour réaliser ça, j&#8217;avais besoin de modifier le code HTML que Symfony m&#8217;avait gentiment généré.</p>
<p>Et donc là, je me suis lancé dans une session de formatting grâce au sfFormatter. En effet, Symfony intègre en règle générale un code HTML par défaut, pour un peu tout, mais nous laisse parfaitement la possibilité de le modifier. Ici, je veux juste pouvoir rajouter une class CSS différente pour les éléments pair et impair. On va donc réécrire la fonction de formatting du widget comme ceci:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'reponses'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'multiple'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
      	<span style="color: #0000ff;">'expanded'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'choices'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$reponses</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'renderer_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'formatter'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'formatter'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Ici on passe l'option formatter avec comme valeur la fonction formatter que l'on va ajouter à notre formulaire</span>
      <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Puis maintenant, on ajoute la fameuse fonction. J&#8217;ai choisi ici de la laisser dans mon formulaire, on peut très bien la mettre où on veut:</p>

<div class="wp_syntax"><div class="code"><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> formatter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget</span><span style="color: #339933;">,</span> <span style="color: #000088;">$inputs</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$rows</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;">$inputs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$input</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$rows</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$widget</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderContentTag</span><span style="color: #009900;">&#40;</span>
        	  <span style="color: #0000ff;">'li'</span><span style="color: #339933;">,</span> 
                  <span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'input'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$widget</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'label_separator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                  <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</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;">'pair'</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;">'impair'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//Seule réelle modification par rapport à la fonction définie de base dans la classe sfWidgetFormSelectCheckbox</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;">$widget</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderContentTag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ul'</span><span style="color: #339933;">,</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'separator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rows</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;">'radio_list'</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></div></div>

<p>Et voilà mon code HTML ressemble maintenant à:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;ul class=&quot;radio_list&quot;&gt;
&lt;li class=&quot;impair&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_7&quot; value=&quot;7&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_7&quot;&gt;Oula&lt;/label&gt;&lt;/li&gt;
&lt;li class=&quot;pair&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_8&quot; value=&quot;8&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_8&quot;&gt;Ola&lt;/label&gt;&lt;/li&gt;
&lt;li class=&quot;impair&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_9&quot; value=&quot;9&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_9&quot;&gt;Woot&lt;/label&gt;&lt;/li&gt;
&lt;li class=&quot;pair&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_10&quot; value=&quot;10&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_10&quot;&gt;Wagli&lt;/label&gt;&lt;/li&gt;
&lt;li class=&quot;impair&quot;&gt;&lt;input type=&quot;checkbox&quot; id=&quot;etude_question_2_reponses_11&quot; value=&quot;11&quot; name=&quot;etude[question_2][reponses][]&quot;/&gt; &lt;label for=&quot;etude_question_2_reponses_11&quot;&gt;Plop&lt;/label&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></div></div>

<p>Je peux maintenant appliquer mon CSS pour faire la modification demandée à l&#8217;origine! Cette astuce fonctionne pour tous les widgets qui embarque du html autre que le simple tag input.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/personnaliser-le-code-html-dun-widget-symfony/2009/06/02/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Effectuer un pré et/ou post traitement dans vos actions Symfony</title>
		<link>http://www.amicalement-web.net/effectuer-un-pre-et-ou-post-traitement-dans-vos-actions/2009/05/01/</link>
		<comments>http://www.amicalement-web.net/effectuer-un-pre-et-ou-post-traitement-dans-vos-actions/2009/05/01/#comments</comments>
		<pubDate>Fri, 01 May 2009 11:10:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=209</guid>
		<description><![CDATA[ Dans le genre, méthode symfony dont on ne parle pas qui peuvent être utiles, voici preExecute et son copain postExecute toutes les deux, méthodes de sfAction.
Comme leur nom le laisse à penser, ce sont des méthodes qui seront appeler en amont et en aval de l&#8217;exécution d&#8217;une action. Je n&#8217;ai pas vraiment d&#8217;idée d&#8217;utilisation [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/dialog-information.png" alt="dialog-information" title="dialog-information" width="48" height="48" class="alignleft size-full wp-image-33" /> Dans le genre, méthode symfony dont on ne parle pas qui peuvent être utiles, voici <a  href="http://www.symfony-project.org/api/1_2/sfAction#method_preexecute" class="extern">preExecute</a> et son copain <a  href="http://www.symfony-project.org/api/1_2/sfAction#method_postexecute" class="extern">postExecute</a> toutes les deux, méthodes de sfAction.</p>
<p>Comme leur nom le laisse à penser, ce sont des méthodes qui seront appeler en amont et en aval de l&#8217;exécution d&#8217;une action. Je n&#8217;ai pas vraiment d&#8217;idée d&#8217;utilisation à l&#8217;heure où j&#8217;écris mais dans un souci de factorisation, je trouve le concept intéressant et c&#8217;est bien avec ce genre de méthodes que je trouve Symfony si bien pensé. </p>
<p>Quelqu&#8217;un s&#8217;en est déjà servi? Une utilisation intéressante qui gagne à être connue?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/effectuer-un-pre-et-ou-post-traitement-dans-vos-actions/2009/05/01/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Prenez le contrôle de votre CSS</title>
		<link>http://www.amicalement-web.net/prenez-le-controle-de-votre-css/2009/02/19/</link>
		<comments>http://www.amicalement-web.net/prenez-le-controle-de-votre-css/2009/02/19/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 10:38:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=125</guid>
		<description><![CDATA[ Votre projet est en plein sprint, les releases de corrections s&#8217;enchainent et vous devez soumettre le résultat à chaque fois à votre client. Et pourtant il y a un mécanisme des navigateurs qu&#8217;on adore en tant qu&#8217;utilisateur mais qui gène parfois en tant que développeur, la mise en cache des CSS.
Quoi de plus frustrant [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/applications-system.png" alt="applications-system" title="applications-system" width="48" height="48" class="alignleft size-full wp-image-31" /> Votre projet est en plein sprint, les releases de corrections s&#8217;enchainent et vous devez soumettre le résultat à chaque fois à votre client. Et pourtant il y a un mécanisme des navigateurs qu&#8217;on adore en tant qu&#8217;utilisateur mais qui gène parfois en tant que développeur, la mise en cache des CSS.</p>
<p>Quoi de plus frustrant d&#8217;avoir en premier retour de votre client <quote>Euh, pourquoi l&#8217;image est au milieu de l&#8217;écran?</quote> alors que vous venez de passer les dernières heures à la mettre au bon endroit en retouchant votre CSS. Bien sûr vous lancez rapidement le cri de guerre adéquat <quote>F5!</quote> et la magie opère enfin.</p>
<p>Mais ne serait-il pas plus plaisant que d&#8217;obtenir dès le premier clic, le bon résultat?<br />
Il y a pour cela une astuce, que bon nombre connaisse, mais qui dans un contexte de développement professionnel, est souvent lourde à mettre en place: changer le nom de votre CSS pour forcer le navigateur à la recharger et ainsi laisser apparaitre vos modifications du premier coup.<br />
<span id="more-125"></span><br />
Évidemment, un changement de nom complet n&#8217;est pas pensable et d&#8217;ailleurs, il suffit de peu en fait.<br />
En effet pour un navigateur les 2 inclusions suivantes sont différentes</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;/css/main.css?1&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span>=<span style="color: #ff0000;">&quot;all' /&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;/css/main.css?2&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span>=<span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>On utilise ainsi tout simplement le passage de paramètre HTTP, et tous nos navigateurs penseront que la CSS a changé car l&#8217;url est différente alors qu&#8217;en fait ce n&#8217;est que poudre aux yeux!</p>
<p>Dans le cadre d&#8217;un projet amateur, on pourrait penser que gérer ce &laquo;&nbsp;versionning&nbsp;&raquo; de CSS à la main n&#8217;est pas insurmontable mais en entreprise, on aura vite faite de s&#8217;en passer si ce n&#8217;est pas automatisé.</p>
<p>Voyons comment y remédier sur Symfony par exemple. La définition des CSS se fait dans le view.yml de notre application:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">default:
  stylesheets:    [main]</pre></div></div>

<p>donne comme résultat:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span>=<span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;/css/main.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Et là, on se dit Euréka! Car oui on peut écrire du PHP dans les fichiers YML de Symfony, directement. Sachant qu&#8217;en environnement de production ces fichiers de configurations ne sont générés qu&#8217;au clean du cache, on peut très bien écrire alors:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">default:
  stylesheets:    [main.css?&lt;?php echo time() ?&gt;]</pre></div></div>

<p>Et notre CSS changera alors de nom à chaque fois que nous viderons le cache. Certes, ce n&#8217;est certainement pas le moyen le plus optimisé car notre CSS ne change pas vraiment à chaque clean de cache, mais son coup de mise en place reste anecdotique pour le résultat obtenu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/prenez-le-controle-de-votre-css/2009/02/19/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE6 sur Mac OS X, quand Linux inspire Mac</title>
		<link>http://www.amicalement-web.net/ie6-sur-mac-os-x-quand-linux-inspire-mac/2009/02/18/</link>
		<comments>http://www.amicalement-web.net/ie6-sur-mac-os-x-quand-linux-inspire-mac/2009/02/18/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 10:56:46 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Bons plans]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[navigateur]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=119</guid>
		<description><![CDATA[ Tous les Linuxiens, en particulier les développeurs web ont du passer le pas un jour, installer une solution le permettant de tester leur page web dans ces magnifique navigateurs qui ralentissent l&#8217;avancée technologique du web, j&#8217;ai nommée IE6 et IE7.
Là où la virtualisation se banalise grâce à des logiciels comme VirtualBox, certains utilisent encore [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/applications-internet.png" alt="applications-internet" title="applications-internet" width="48" height="48" class="alignleft size-full wp-image-29" /> Tous les Linuxiens, en particulier les développeurs web ont du passer le pas un jour, installer une solution le permettant de tester leur page web dans ces magnifique navigateurs qui ralentissent l&#8217;avancée technologique du web, j&#8217;ai nommée IE6 et IE7.</p>
<p>Là où la <a  href="http://fr.wikipedia.org/wiki/Virtualisation" class="extern">virtualisation</a> se banalise grâce à des logiciels comme <a  href="http://www.virtualbox.org/" class="extern">VirtualBox</a>, certains utilisent encore des émulateurs dont le célèbre <a  href="http://www.tatanka.com.br/ies4linux/page/Main_Page" class="extern">ie4linux</a>.</p>
<p>Et bien, l&#8217;alternative pour Mac OS X existe, preuve que la pomme a quand même bien fait les choses. Et pour l&#8217;installer rien de plus simple.<br />
<span id="more-119"></span><br />
Commençons par s&#8217;assurer que nous disposons de X11 qui sera utilisé pour afficher la fenêtre de notre futur IE6. Si vous ne l&#8217;avez pas spécifié à l&#8217;installation de Léopard, il  faudra l&#8217;installer via <a  href="http://developer.apple.com/tools/xcode/" class="extern">Xcode</a>, mais que tout bon développeur sous Mac aura déjà installé. L&#8217;application X11 devrait donc se situer dans Applications > Utilitaires</p>
<p>Ensuite, installer <a  href="http://www.kronenberg.org/darwine/" class="extern">Darwine</a> (via un joli .dmg et un simple glissez/déposer à la mac), qui n&#8217;est d&#8217;autre qu&#8217;un portage de Wine sur Mac OS X. </p>
<p>Maintenant tous les exe seront ouvert via Darwine. Il ne vous reste plus qu&#8217;à installer <a  href="http://www.kronenberg.org/ies4osx/" class="extern">ie4osx</a> et voilà le travail:<br />
<a  href="http://www.amicalement-web.net/wp-content/uploads/image-11.png"><img src="http://www.amicalement-web.net/wp-content/uploads/image-11-300x229.png" alt="image-11" title="image-11" width="300" height="229" class="alignnone size-medium wp-image-121" /></a></p>
<p>Alors ça reste moche hein, Mac ne fait pas de miracle, mais ca permet de dépanner rapidement pour des tests bateau, quand vous ne faites qu&#8217;assurer le service minimum pour ce navigateur ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/ie6-sur-mac-os-x-quand-linux-inspire-mac/2009/02/18/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Pour un web à son image, Smush it!</title>
		<link>http://www.amicalement-web.net/pour-un-web-a-son-image-smush-it/2009/01/27/</link>
		<comments>http://www.amicalement-web.net/pour-un-web-a-son-image-smush-it/2009/01/27/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 20:04:48 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Bons plans]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=10</guid>
		<description><![CDATA[ Un autre domaine assez controversé dans le web, ce sont les formats d&#8217;images. Bien longtemps, grand chouchou des webmaster, le GIF a régné en maître, de part sa technologie, une compression sans perte qui gèrait le canal alpha et même l&#8217;animation! 
Son principal problème était son brevet, qui a trainé jusqu&#8217;en 2004, le rendant [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/applications-internet.png" alt="applications-internet" title="applications-internet" width="48" height="48" class="alignleft size-full wp-image-29" /> Un autre domaine assez controversé dans le web, ce sont les formats d&#8217;images. Bien longtemps, grand chouchou des webmaster, le <a  href="http://fr.wikipedia.org/wiki/Graphics_Interchange_Format" class="extern">GIF</a> a régné en maître, de part sa technologie, une compression sans perte qui gèrait le canal alpha et même l&#8217;animation! </p>
<p>Son principal problème était son brevet, qui a trainé jusqu&#8217;en 2004, le rendant ennemi numéro 1 des libristes du web. Pendant ce temps, tapis dans l&#8217;ombre, le <a  href="http://fr.wikipedia.org/wiki/Portable_Network_Graphics" class="extern">PNG</a> a commencé à monter en puissance, d&#8217;abord appuyé par le W3C puis certifié ISO en 2004. </p>
<p>Son principal intérêt, un gif amélioré et un <a  href="http://fr.wikipedia.org/wiki/Format_ouvert" class="extern">format ouvert</a>. Amélioré car il ne s&#8217;arrête pas aux 8bits de couleurs du GIF, mais va jusqu&#8217;à 32, permettant même de gérer totalement la transparence d&#8217;une image et à image égale il surpasse le GIF en poids d&#8217;image.</p>
<p>Malheureusement, trop mis en avant dès sa sortie, le PNG a été proclamé messie et tueur également du format <a  href="http://fr.wikipedia.org/wiki/JPEG" class="extern">JPEG</a> alors qu&#8217;il n&#8217;en avait pas la possibilité. En effet, le jpeg tire son succès dans la compression de photo, là où son algorithme de compression avec perte (grosse différence comparé au PNG) pouvait pleinement s&#8217;exprimer. A photo égale, le PNG se retrouve donc logiquement loin derrière.</p>
<p>On l&#8217;a alors rangé dans le catalogue format non optimisé, trop lourd, sans compter avec ces <a  href="http://openweb.eu.org/articles/png_vs_gif" class="extern">problèmes relationnels avec Photoshop et Internet Explorer</a>.</p>
<p>Mais comme tous les formats ouverts, le PNG a ses fans et certains réalisent des choses assez folles comme ce cher <a  href="http://smushit.com/">Smush it</a> qui permet en 1 clic après installation du plugin firefox correspondant d&#8217;optimiser toutes les images d&#8217;un site, vous les mettant alors à disposition, et en PNG bien sûr.</p>
<p>Voila le résultat pour amicalement web:<br />
<img src="http://www.amicalement-web.net/wp-content/uploads/image-28.png" alt="image-28" title="image-28" width="477" height="123" class="alignnone size-full wp-image-45" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/pour-un-web-a-son-image-smush-it/2009/01/27/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Que fait la police sous Linux</title>
		<link>http://www.amicalement-web.net/que-fait-la-police-sous-linux/2009/01/26/</link>
		<comments>http://www.amicalement-web.net/que-fait-la-police-sous-linux/2009/01/26/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 18:13:03 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Bons plans]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=18</guid>
		<description><![CDATA[Un des principaux manques actuels du CSS 2, c&#8217;est bien la gestion de la police. 
Il n&#8217;est pas encore possible d&#8217;imposer une police à l&#8217;internaute[1] mais seulement de lui en suggérer un certain nombre que le navigateur parsera dans l&#8217;ordre donné jusqu&#8217;à en trouver une que le système d&#8217;exploitation possède. Mais avec la montée en [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/applications-system.png" alt="applications-system" title="applications-system" width="48" height="48" class="alignleft size-full wp-image-31" />Un des principaux manques actuels du CSS 2, c&#8217;est bien la gestion de la police. </p>
<p>Il n&#8217;est pas encore possible d&#8217;imposer une police à l&#8217;internaute<sup>[1]</sup> mais seulement de lui en suggérer un certain nombre que le navigateur parsera dans l&#8217;ordre donné jusqu&#8217;à en trouver une que le système d&#8217;exploitation possède. Mais avec <a  href="http://www.xitimonitor.com/fr-fr/equipement-internaute/systemes-d-exploitation-aout-2008/index-1-1-7-143.html" class="extern">la montée en puissance</a>, lente mais régulière des systèmes autre que Windows, il peut devenir un vrai casse-tête de trouver une police un peu évoluée que chacun pourra afficher.</p>
<p>En fait le problème se pose surtout pour les linuxiens, et même le paquet <a  href="http://doc.ubuntu-fr.org/msttcorefonts">msttcorefonts</a> ne résous pas ce problème entièrement, en plus d&#8217;obliger les partisans du pingouin à installer un paquet supplémentaire.</p>
<p>Mais le web regorge de bonnes volontés, et je suis tombé sur un billet en anglais qui <a  href="http://mondaybynoon.com/2007/04/02/linux-font-equivalents-to-popular-web-typefaces/" class="extern">tente de trouver des équivalents</a> à ce cher Arial, Helvetica, Lucida sous linux en natif.</p>
<p>Au final, j&#8217;ai opté personnellement pour le couple Lucida Sans/Mukti Narrow pour le texte et Helvetica/FreeSans pour les titres. Après quelques tests, le résultat est tout à fait acceptable sur mon Ubuntu et permet de garder un peu plus le contrôle sur la charte graphique désirée.</p>
<ol class="footnotes"><li id="footnote_0_18" class="footnote"><a  href="http://www.css3.info/more-type-control-with-css3-fonts/">C&#8217;est tout de même en projet sérieusement dans CSS3</a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/que-fait-la-police-sous-linux/2009/01/26/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplifiez vos conditions</title>
		<link>http://www.amicalement-web.net/simplifiez-vos-conditions/2009/01/25/</link>
		<comments>http://www.amicalement-web.net/simplifiez-vos-conditions/2009/01/25/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 19:05:50 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.amicalement-web.net/?p=5</guid>
		<description><![CDATA[Les conditions font partie intégrante de tous les langages de programmation, PHP ne déroge pas à la règle.
Cependant il n&#8217;est pas rare qu&#8217;elles gâchent la lisibilité d&#8217;un code quand elles s&#8217;imbriquent ou quand les différents états sont à plusieurs dizaines de lignes d&#8217;écart.
Un moyen simple d&#8217;y voir plus clair et de tourner vos conditions différemment.
Par [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amicalement-web.net/wp-content/uploads/accessories-text-editor.png" alt="accessories-text-editor" title="accessories-text-editor" width="48" height="48" class="alignleft size-full wp-image-28" />Les conditions font partie intégrante de tous les langages de programmation, PHP ne déroge pas à la règle.</p>
<p>Cependant il n&#8217;est pas rare qu&#8217;elles gâchent la lisibilité d&#8217;un code quand elles s&#8217;imbriquent ou quand les différents états sont à plusieurs dizaines de lignes d&#8217;écart.</p>
<p>Un moyen simple d&#8217;y voir plus clair et de tourner vos conditions différemment.</p>
<p>Par exemple, on a souvent tendance à écrire:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$condition</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/* Tout mon traitement qui peut faire plusieurs dizaines de ligne */</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;">/* Traitement de l'erreur, par exemple */</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Au final, la condition n&#8217;est utilisée que pour gérer le cas d&#8217;erreur, mais celui-ci se retrouve retranché en bas de script.</p>
<p>Pour gagner en lisibilité, on pourrait donc écrire:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$condition</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/* Traitement de l'erreur, par exemple */</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* Tout mon traitement qui peut faire plusieurs dizaines de ligne */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>La gestion de notre erreur, est maintenant dans la continuité de notre script et se révèle beaucoup plus confortable à lire. Attention toutefois, ce genre de pratique demande à ce que votre gestion d&#8217;erreur coupe l&#8217;exécution du script avec en général l&#8217;utilisation de <code>return</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amicalement-web.net/simplifiez-vos-conditions/2009/01/25/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
