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

<channel>
	<title>Blog Symfony2 - Lexik Montpellier &#187; laurent</title>
	<atom:link href="http://www.lexik.fr/blog/symfony/author/laurent/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lexik.fr/blog/symfony</link>
	<description>Blog sur le développement Web PHP avec Symfony 2</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:00:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Installation de SuPHP sur Ubuntu</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/installation-de-suphp-sur-ubuntu-1665</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/installation-de-suphp-sur-ubuntu-1665#comments</comments>
		<pubDate>Fri, 26 Aug 2011 08:00:40 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1665</guid>
		<description><![CDATA[Un problème récurrent pour beaucoup de développeurs utilisant Symfony est l&#8217;éternel conflit avec l&#8217;utilisateur &#171;&#160;www-data&#160;&#187; lors des accès, par exemple, aux fichiers du cache et aux logs. Sur Symfony 2 ce problème devient encore plus visible avec l&#8217;utilisation massive du &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/installation-de-suphp-sur-ubuntu-1665">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Un problème récurrent pour beaucoup de développeurs utilisant Symfony est l&#8217;éternel conflit avec l&#8217;utilisateur &laquo;&nbsp;www-data&nbsp;&raquo; lors des accès, par exemple, aux fichiers du cache et aux logs. Sur Symfony 2 ce problème devient encore plus visible avec l&#8217;utilisation massive du répertoire cache même en environnement &laquo;&nbsp;dev&nbsp;&raquo;.</p>
<p>Le cas de conflit le plus flagrant est certainement le <code>app/console cache:clear</code> qui renvoie une erreur car le cache a été généré par www-data lors du chargement du site par apache. Le bon gros <code>sudo rm -rf app/cache/*</code> n&#8217;est pas une solution acceptable, tout juste une rustine.<span id="more-1665"></span></p>
<p>Il existe différents moyens d&#8217;éviter ces conflits, que ce soit via scripts personnalisés, configurations avancées, ou packages additionnels. SuPHP est un module pour Apache très facile à mettre en place pour un environnement de &laquo;&nbsp;dev&nbsp;&raquo;, et il va répondre à notre problème d&#8217;une manière très simple: Apache ne va plus éxécuter les sites via &#8216;www-data&#8217;, mais via l&#8217;utilisateur propriétaire des fichiers éxécutés, c&#8217;est-à-dire le plus souvent le compte du développeur.</p>
<p>L&#8217;installation comprend deux packages dispos sur synaptic ou directement depuis la console:</p>
<pre>sudo apt-get install suphp-common libapache2-mod-suphp</pre>
<p>Pour une station de dev, une configuration fonctionnelle et simple est très bien décrite sur <a href="http://doc.ubuntu-fr.org/suphp#installation_de_suphp">http://doc.ubuntu-fr.org/suphp#installation_de_suphp</a>. Cette configuration empêche l&#8217;intervention de suphp dans les répertoires de /usr/share pour permettre entre autres à phpmyadmin (dans son emplacement par défaut) de continuer à fonctionner sans problèmes.</p>
<p>Il faudra éventuellement supprimer les fichiers de sessions en cours appartenent encore à www-data (dans /var/lib/php5 par défaut).</p>
<p>Si vos projets ne sont pas stockés dans les répertoires /var/www ou ~/public_html, il faut éditer la valeur de &laquo;&nbsp;docroot&nbsp;&raquo; dans /etc/suphp/suphp.conf pour y ajouter les répertoires supplémentaires. Par exemple, mes projets sont dans ~/www/ :</p>
<pre>docroot=/var/www:${HOME}/public_html</pre>
<p>devient alors:</p>
<pre>docroot=/var/www:${HOME}/public_html:${HOME}/www</pre>
<p>Pensez à nettoyer vos fichiers appartenant encore à www-data (cette fois avec des <code>sudo rm</code> par contre), comme les répertoires cache et logs, et redémarrez simplement Apache (<code>sudo service apache2 restart</code>). Après ça vous ne devriez plus voir de www-data dans vos projets, et vous pourrez oublier ce mauvais réflexe du <code>sudo rm -rf</code> à tout bout de champ !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/installation-de-suphp-sur-ubuntu-1665/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Survol de la GoogleMaps Api v3</title>
		<link>http://www.lexik.fr/blog/symfony/javascript/survol-de-la-googlemaps-api-v3-1509</link>
		<comments>http://www.lexik.fr/blog/symfony/javascript/survol-de-la-googlemaps-api-v3-1509#comments</comments>
		<pubDate>Fri, 11 Mar 2011 10:30:04 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[geolocalisation]]></category>
		<category><![CDATA[google api]]></category>
		<category><![CDATA[googlemaps]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1509</guid>
		<description><![CDATA[Beaucoup d&#8217;entre vous ont certainement déjà eu l&#8217;occasion de jouer avec l&#8217;api javascript de GoogleMaps. Elle est performante, bien documentée, et plutôt instinctive à implémenter. De plus il éxiste énormément de ressources sur le web proposant des exemples d&#8217;utilisation. On &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/javascript/survol-de-la-googlemaps-api-v3-1509">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Beaucoup d&#8217;entre vous ont certainement déjà eu l&#8217;occasion de jouer avec l&#8217;api javascript de GoogleMaps. Elle est performante, bien documentée, et plutôt instinctive à implémenter. De plus il éxiste énormément de ressources sur le web proposant des exemples d&#8217;utilisation.<br />
On trouve cependant encore peu de ressources mentionnant la dernière mouture de l&#8217;api, la v3, qui simplifie et éclaircie encore plus son utilisation. Ce petit article va survoler quelques exemples d&#8217;utilisation de celle-ci.</p>
<p><span id="more-1509"></span></p>
<p><strong>La première grosse nouveauté de la v3, c&#8217;est la mort de la clé api !</strong> En effet, il n&#8217;est plus nécessaire de déclarer un domaine pour récupérer une clé, ou de se battre avec tout un trousseau pour jongler entre des environnements de dev, preprod, prod, test, etc&#8230; Maintenant on charge simplement l&#8217;api comme n&#8217;importe quelle librairie Javascript.<br />
Second changement notoire, plus aucun appel Ajax explicite vers l&#8217;api REST n&#8217;est nécessaire pour récupérer des données de géolocalisation. Un simple passage de paramètres à des objets Javascript nous rendra les informations voulues en un temps record.</p>
<p>Commençons donc par charger l&#8217;api et afficher une map:</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('p1509code9'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15099"><td class="code" id="p1509code9"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;gmap-div&quot;</span> style<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;width: 500px; height: 400px;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://maps.google.com/maps/api/js?sensor=false&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</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;">//J'utilise dans l'exemple jQuery pour améliorer la lisibilité du code, le focus étant sur GoogleMaps</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//tout d'abord on définit le centre de notre map par sa latitude et longitude, par exemple Montpellier: </span>
  <span style="color: #003366; font-weight: bold;">var</span> latLng <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">43.60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3.88</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">//puis on créé la map</span>
  <span style="color: #003366; font-weight: bold;">var</span> gmap <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'gmap-div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    zoom<span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//le zoom de départ</span>
    center<span style="color: #339933;">:</span> latLng<span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//le centre de la map au chargement</span>
    mapTypeId<span style="color: #339933;">:</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MapTypeId</span>.<span style="color: #660066;">ROADMAP</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//le type de map, ROADMAP correspond à la version par défaut des versions précédentes</span>
    streetViewControl<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//si on souhaite désactiver les contrôle StreetView</span>
    panControl<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #006600; font-style: italic;">//si on souhaite masquer les contrôles de déplacement</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Créons maintenant quelques interactions. Pour commencer un formulaire va nous permettre de rechercher une ville pour ensuite placer un marqueur à son emplacement sur la map:</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('p1509code10'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150910"><td class="code" id="p1509code10"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;search-form&quot; action=&quot;#&quot;&gt;
  &lt;input type=&quot;text&quot; id=&quot;search-query&quot; size=&quot;20&quot; /&gt;
  &lt;input type=&quot;submit&quot; value=&quot;chercher&quot; /&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>Et le code javascript correspondant:</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('p1509code11'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150911"><td class="code" id="p1509code11"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//on créé un geocoder qui s'occupera des requètes de géolocalisation</span>
<span style="color: #003366; font-weight: bold;">var</span> geocoder <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Geocoder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#search-form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//l'objet request que l'on passe au geocoder</span>
  <span style="color: #003366; font-weight: bold;">var</span> request <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    address<span style="color: #339933;">:</span>    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#search-query'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    region<span style="color: #339933;">:</span>     <span style="color: #3366CC;">'fr'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//pour améliorer la qualité des résultats en précisant que l'on cherche principalement en France</span>
    language<span style="color: #339933;">:</span>   <span style="color: #3366CC;">'fr'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">//aucune requète ajax nécessaire !</span>
  geocoder.<span style="color: #660066;">geocode</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> <span style="color: #000066;">status</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: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'OK'</span> <span style="color: #339933;">&amp;&amp;</span> results.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">//on récupère les coordonnées du premier résultat</span>
      <span style="color: #003366; font-weight: bold;">var</span> lat <span style="color: #339933;">=</span> results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span>.<span style="color: #660066;">lat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> lng <span style="color: #339933;">=</span> results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span>.<span style="color: #660066;">lng</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//puis on recentre la map...</span>
      <span style="color: #003366; font-weight: bold;">var</span> newCenter <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>lat<span style="color: #339933;">,</span> lng<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      gmap.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>newCenter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//...et on pose un marqueur dessus</span>
      <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	position<span style="color: #339933;">:</span>  newCenter<span style="color: #339933;">,</span>
        map<span style="color: #339933;">:</span>       gmap
      <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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aucun résultat'</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></pre></td></tr></table></div>

<p>Plutôt simple pour l&#8217;instant. Allons un peu plus loin et traçons une ligne qui va relier au fur et à mesure toutes les villes marquées. Il va falloir pour cela utiliser la librairie supplémentaire de GoogleMaps &laquo;&nbsp;Geometry&nbsp;&raquo;. N&#8217;étant pas une librairie chargée par défaut, il faut préciser son utilisation au chargement de GoogleMaps:</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('p1509code12'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150912"><td class="code" id="p1509code12"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.google.com/maps/api/js?libraries=geometry&amp;sensor=false&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Profitons-en pour afficher la longueur en kilomètre de notre itinéraire dans une div que l&#8217;on va tout de suite rajouter au document:</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('p1509code13'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150913"><td class="code" id="p1509code13"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;total-length&quot;&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>Pour tracer une ligne reliant des points sur une GoogleMap, il faut utiliser la classe &laquo;&nbsp;Polyline&nbsp;&raquo;. Déclarons-la juste après la map en début de script:</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('p1509code14'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150914"><td class="code" id="p1509code14"><pre class="javascript" style="font-family:monospace;">  <span style="color: #009966; font-style: italic;">/* ... */</span>
  <span style="color: #003366; font-weight: bold;">var</span> polyline <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Polyline</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    strokeColor<span style="color: #339933;">:</span>   <span style="color: #3366CC;">'#2222FF'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//on définit la couleur</span>
    strokeOpacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.5</span><span style="color: #339933;">,</span>       <span style="color: #006600; font-style: italic;">//l'opacité</span>
    strokeWeight<span style="color: #339933;">:</span>  <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>         <span style="color: #006600; font-style: italic;">//l'épaisseur du trait,</span>
    map<span style="color: #339933;">:</span>           gmap       <span style="color: #006600; font-style: italic;">//la map à laquelle rattacher la polyline</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;">//on peut extraire un objet renfermant tous les points d'une Polyline</span>
  <span style="color: #006600; font-style: italic;">//cet objet nous sera utile pour calculer la distance de l'itinéraire</span>
  <span style="color: #003366; font-weight: bold;">var</span> path <span style="color: #339933;">=</span> polyline.<span style="color: #660066;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Il faut maintenant étoffer le code de création du marqueur:</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('p1509code15'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150915"><td class="code" id="p1509code15"><pre class="javascript" style="font-family:monospace;">  <span style="color: #009966; font-style: italic;">/* ... */</span>
  geocoder.<span style="color: #660066;">geocode</span><span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> <span style="color: #000066;">status</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: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'OK'</span> <span style="color: #339933;">&amp;&amp;</span> results.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> lat <span style="color: #339933;">=</span> results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span>.<span style="color: #660066;">lat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> lng <span style="color: #339933;">=</span> results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span>.<span style="color: #660066;">lng</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">var</span> newCenter <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>lat<span style="color: #339933;">,</span> lng<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      gmap.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>newCenter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        position<span style="color: #339933;">:</span>  newCenter<span style="color: #339933;">,</span>
        map<span style="color: #339933;">:</span>       gmap
      <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;">//on ajoute le nouveau point à notre path, le Polyline associé se met automatiquement à jour</span>
      path.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>newCenter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//on affiche la longueur du path dans notre div</span>
      <span style="color: #006600; font-style: italic;">//c'est ici qu'intervient la librairie Geometry, qui va gérer automatiquement tous les calculs nécessaires</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">var</span> pathLength <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">spherical</span>.<span style="color: #660066;">computeLength</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">//computeLength nous renvoie des mètres que l'on transforme en kilomètres</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//on met à jour l'affichage</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#total-length'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>pathLength <span style="color: #339933;">+</span> <span style="color: #3366CC;">' km'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aucun résultat'</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: #006600; font-style: italic;">/* ... */</span></pre></td></tr></table></div>

<p>Il a suffi d&#8217;une poignée de lignes pour rajouter ces informations, et le résultat est plutôt sympathique.</p>
<p>On remarque tout de même un détail ennuyeux: il faut déplacer et zoomer à la main si on veut avoir une vue globale et centrée de notre itinéraire à chaque nouvel ajout de marqueur. A la manière du &laquo;&nbsp;path&nbsp;&raquo; qui stocke les informations d&#8217;une Polyline, une map possède des &laquo;&nbsp;bounds&nbsp;&raquo; qui définissent les limites de son affichage. La classe &laquo;&nbsp;LatLngBounds&nbsp;&raquo; arrive ici en jeu et va nous permettre d&#8217;optimiser automatiquement l&#8217;affichage de notre itinéraire.</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('p1509code16'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p150916"><td class="code" id="p1509code16"><pre class="javascript" style="font-family:monospace;">  <span style="color: #006600; font-style: italic;">//en début de script avec les déclarations, on créé notre objet bounds</span>
  <span style="color: #003366; font-weight: bold;">var</span> bounds <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLngBounds</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009966; font-style: italic;">/* ... */</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//à la suite de l'ajout d'un nouveau marqueur, on étend la zone &quot;bounds&quot; en lui demandant d'inclure le nouveau point</span>
  bounds.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>newCenter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">//on demande en suite à la map de s'adapter à cette zone</span>
  gmap.<span style="color: #660066;">fitBounds</span><span style="color: #009900;">&#40;</span>bounds<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">/* ... */</span></pre></td></tr></table></div>

<p>Et c&#8217;est tout ! Encore trois malheureuses lignes pour une fonctionnalité relativement puissante. Vous pouvez voir l&#8217;exemple tourner <a href="http://www.lexik.fr/sandbox/1509_exemple_googlemaps_v3.html">sur cette page</a>.</p>
<p>La richesse de cette dernière version de l&#8217;api, couplée à la fluidité de son utilisation, rend l&#8217;intégration d&#8217;une GoogleMap dans une application riche vraiment agréable. Jetez un oeil à la <a href="http://code.google.com/intl/fr/apis/maps/documentation/javascript/basics.html">documentation officielle</a> très complète si vous souhaitez en apprendre plus !</p>
<p>Les sources de l&#8217;exemple de cet article sont disponibles <a href="https://gist.github.com/865652">sur Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/javascript/survol-de-la-googlemaps-api-v3-1509/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Présentation du plugin lxJavascriptPlugin</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/presentation-du-plugin-lxjavascriptplugin-1408</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/presentation-du-plugin-lxjavascriptplugin-1408#comments</comments>
		<pubDate>Tue, 18 Jan 2011 09:53:28 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Méthodologie]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[error]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1408</guid>
		<description><![CDATA[L&#8217;article d&#8217;hier sur les bonnes pratiques Javascript dans un projet Symfony faisait mention d&#8217;un plugin que nous utilisons en interne et qui est maintenant disponible sur Github: lxJavascriptPlugin. Ce court article va brièvement présenter son fonctionnement et son utilisation. L&#8217;installation &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/presentation-du-plugin-lxjavascriptplugin-1408">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>L&#8217;article d&#8217;hier sur les bonnes pratiques Javascript dans un projet Symfony faisait mention d&#8217;un plugin que nous utilisons en interne et qui est maintenant disponible sur Github: lxJavascriptPlugin. Ce court article va brièvement présenter son fonctionnement et son utilisation.</p>
<p><span id="more-1408"></span></p>
<p>L&#8217;installation du plugin est très rapide:</p>
<ul>
<li>téléchargez <a href="https://github.com/lexik/lxJavascriptPlugin" target="_blank">les sources sur Github</a> dans le répertoire plugins de votre projet,</li>
<li>éditez le fichier config/settings.yml pour y inclure le helper lxJavascript:

<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('p1408code25'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140825"><td class="code" id="p1408code25"><pre class="yml" style="font-family:monospace;">all:
  .settings:
    standard_helpers: [ ... , lxJavascript ]</pre></td></tr></table></div>

</li>
</ul>
<p>Et c&#8217;est tout! Voyons maintenant le fonctionnement.</p>
<p>Le premier but du plugin est de solutionner les problèmes de granularité du code Javascript dans un projet Symfony. Lorsque l&#8217;on utilise par exemple des widgets JQuery, des partials pour les réseaux sociaux, ou des composants pour des GoogleMap, on se retrouve vite avec du code Javascript éparpillé dans tout notre projet, et par conséquent tout autant éparpillé dans le code des pages générées.</p>
<p>Pour régler ce problème lxJavascriptPlugin propose un premier outil: le helper lxJavascriptHelper. Son utilisation est très similaire à celle du javascriptHelper de Symfony, mais avec la méthode lx_javascript:</p>
<ul>
<li>pour inclure un fichier source externe à la page:

<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('p1408code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140826"><td class="code" id="p1408code26"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> lx_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</li>
<li>pour inclure directement du code javascript, par exemple le bout de code pour Google Analytics, le fonctionnement est similaire à celui d&#8217;un slot:

<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('p1408code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140827"><td class="code" id="p1408code27"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> lx_javascript<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #000000; font-weight: bold;">var</span> _gaq <span style="color: #339933;">=</span> _gaq <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  _gaq<span style="color: #339933;">.</span>push<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'_setAccount'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'*********'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  _gaq<span style="color: #339933;">.</span>push<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'_trackPageview'</span><span style="color: #009900;">&#93;</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;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> ga <span style="color: #339933;">=</span> document<span style="color: #339933;">.</span>createElement<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ga<span style="color: #339933;">.</span>src <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https:'</span> <span style="color: #339933;">==</span> document<span style="color: #339933;">.</span>location<span style="color: #339933;">.</span>protocol ? <span style="color: #0000ff;">'https://ssl'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'http://www'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">'.google-analytics.com/ga.js'</span><span style="color: #339933;">;</span>
    ga<span style="color: #339933;">.</span>setAttribute<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'async'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    document<span style="color: #339933;">.</span>documentElement<span style="color: #339933;">.</span>firstChild<span style="color: #339933;">.</span>appendChild<span style="color: #009900;">&#40;</span>ga<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: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> lx_end_javascript<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Ici la balise &lt;script&gt; n&#8217;est pas nécessaire, mais vous pouvez l&#8217;utiliser si vous le souhaitez (par exemple pour garder la coloration syntaxique de votre IDE)</li>
<li>pour insérer tout le code javascript déclaré via lx_javascript() à la fin de votre layout.php:

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1408code28'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140828"><td class="code" id="p1408code28"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot;&gt;
  &lt;head&gt;
    ...
  &lt;/head&gt;
  &lt;body&gt;
    ...
    &lt;?php lx_include_javascripts() ?&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

</li>
</ul>
<p>Le soucis de javascript dans les templates est adressé. Reste maintenant le problème du code javascript inséré via d&#8217;autres moyens, comme par exemple un widget qui utilise JQuery. Pour cela lxJavascriptPlugin propose une classe statique lxJavascriptStorage qui offre les fonctionnalités du helper depuis n&#8217;importe où dans votre code:</p>
<ul>
<li>pour ajouter une source externe:

<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('p1408code29'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140829"><td class="code" id="p1408code29"><pre class="php" style="font-family:monospace;">lxJavascriptStorage<span style="color: #339933;">::</span><span style="color: #004000;">addRemoteJavascript</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li>pour ajouter du code javascript. Voyons par exemple la méthode render() du widget sfWidgetFormJQueryDate:

<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('p1408code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140830"><td class="code" id="p1408code30"><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> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">//code</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
           <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderTag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'input'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hidden'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_jquery_control'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disabled'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
           <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
  [...]
// ]]&gt;&lt;/script&gt;
EOF</span>
    <span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">//arguments du sprintf</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Nous voyons bien le javascript retourné dans le code du widget, et donc en milieu de page. Cette fonction render() pourrait, avec lxJavascriptPlugin, ressembler à ça:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1408code31'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140831"><td class="code" id="p1408code31"><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> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">//code &lt;/code&gt;</span>
&nbsp;
  <span style="color: #000088;">$js</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOF
&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
  [...]
// ]]&gt;&lt;/script&gt;
EOF</span>
    <span style="color: #339933;">,</span>
    <span style="color: #666666; font-style: italic;">//arguments du sprintf</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lxJavascriptStorage<span style="color: #339933;">::</span><span style="color: #004000;">addJavascriptCode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$js</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>
           <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderTag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'input'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hidden'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'size'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateId</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_jquery_control'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'disabled'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Peu de changements, mais ici le javascript sera rendu avec tout le reste du javascript en pied de page. </code></li>
</ul>
<p>Notez enfin que la méthode lx_include_javascripts() rendra en premier les sources externes, puis le code javascript concaténé dans une unique balise &lt;script&gt;. Si tous les exemples précédents sont utilisés dans une application, le javascript en pied de page donnera 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('p1408code32'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p140832"><td class="code" id="p1408code32"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #006600; font-style: italic;">// &lt;![CDATA[</span>
  <span style="color: #006600; font-style: italic;">//javascript du widget</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> _gaq <span style="color: #339933;">=</span> _gaq <span style="color: #339933;">||</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  _gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_setAccount'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'*********'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  _gaq.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'_trackPageview'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #003366; font-weight: bold;">var</span> ga <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ga.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'https:'</span> <span style="color: #339933;">==</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">protocol</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'https://ssl'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://www'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.google-analytics.com/ga.js'</span><span style="color: #339933;">;</span>
    ga.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'async'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>ga<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: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">/* ]]&gt; */</span><span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
</ul>
<p>Vous pouvez obtenir <a href="https://github.com/lexik/lxJavascriptPlugin">lxJavascriptPlugin sur Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/presentation-du-plugin-lxjavascriptplugin-1408/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Exemple d&#8217;application utilisant la Graph API de Facebook</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/exemple-dapplication-utilisant-la-graph-api-de-facebook-1187</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/exemple-dapplication-utilisant-la-graph-api-de-facebook-1187#comments</comments>
		<pubDate>Wed, 07 Jul 2010 12:42:30 +0000</pubDate>
		<dc:creator>laurent</dc:creator>
				<category><![CDATA[1.4.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[developpeur]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1187</guid>
		<description><![CDATA[Facebook a lancé il y a maintenant quelque smois sa nouvelle Graph API, mais la documentation qui l'entoure se fait encore rare et peu détaillée. Je vais donc profiter de cet article pour présenter quelques aspects de cette nouvelle API à l'aide d'une petite iframe application Facebook, et avec Symfony (pour rester dans la thématique du blog !).<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/exemple-dapplication-utilisant-la-graph-api-de-facebook-1187">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Facebook a lancé il y a maintenant quelques mois sa nouvelle Graph API, qui permet d&#8217;accèder et d&#8217;interagir avec les informations Facebook de l&#8217;utilisateur encore plus simplement. Seuelement la documentation qui l&#8217;entoure se fait encore rare et peu détaillée. Je vais donc profiter de cet article pour présenter quelques aspects de cette nouvelle API à l&#8217;aide d&#8217;une petite iframe application Facebook, et avec Symfony (pour rester dans la thématique du blog !).</p>
<p><span id="more-1187"></span></p>
<p>Pour commencer nous avons bien sûr besoin de créer notre application Facebook. Cela n&#8217;étant pas le but de cet article, je vous laisse trouver la marche à suivre sur le net; les sites couvrant le sujet sont légion (par exemple <a href="http://www.creer-une-application-facebook.com" target="_blank">créer une application Facebook</a>).</p>
<p>On paramètre correctement l&#8217;application et celle-ci s&#8217;occupera ensuite de charger nos pages dynamiques depuis l&#8217;url spécifiée:</p>
<p><a href="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/canvas.png"><img class="alignnone size-medium wp-image-1188" title="canvas" src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/canvas-300x232.png" alt="" width="300" height="232" /></a></p>
<p>L&#8217;application Symfony n&#8217;a ici qu&#8217;un seul module &laquo;&nbsp;demo&nbsp;&raquo; qui s&#8217;occupe des quelques actions nécessaires. Editons &laquo;&nbsp;app.yml&nbsp;&raquo; pour y ajouter l&#8217;ID et le SECRET obtenus lors de la création de notre application:</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('p1187code33'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118733"><td class="code" id="p1187code33"><pre class="yml" style="font-family:monospace;">all:
  facebook:
    app_id: 116399618389033
    api_key: *******************************************
    secret: *****************************************
    base_url: http://facebook.prestataire-symfony.com
    app_url: http://apps.facebook.com/demolexik</pre></td></tr></table></div>

<p>Il nous faut ensuite récupérer <a href="http://github.com/facebook/php-sdk/downloads" target="_blank">l&#8217;api Facebook PHP sur Github</a>, que nous allons coller dans /lib/facebook/facebook.php.<br />
Afin de ne pas avoir à initialiser les appels à l&#8217;api depuis chaque action, un filter va grandement nous simplifier la tâche:</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('p1187code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118734"><td class="code" id="p1187code34"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// lib/filter/FacebookFilter.class.php</span>
<span style="color: #000000; font-weight: bold;">class</span> FacebookFilter <span style="color: #000000; font-weight: bold;">extends</span> sfFilter
<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> execute<span style="color: #009900;">&#40;</span>sfFilterChain <span style="color: #000088;">$filterChain</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//initialisation de l'appel à l'api...</span>
    <span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Facebook<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'appId'</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_facebook_app_id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'secret'</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_facebook_secret'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'cookie'</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;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionStack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLastEntry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$facebook</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$filterChain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Pensez à éditer votre &laquo;&nbsp;filters.yml&nbsp;&raquo; en conséquence.</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('p1187code35'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118735"><td class="code" id="p1187code35"><pre class="yml" style="font-family:monospace;">#apps/frontend/config/filters.yml
rendering: ~
security:  ~
# insert your own filters here
Facebook:
  class: FacebookFilter
cache:     ~
execution: ~</pre></td></tr></table></div>

<p>Pour l&#8217;api Javascript, nous allons éditer le layout de l&#8217;application:</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('p1187code36'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118736"><td class="code" id="p1187code36"><pre class="html" style="font-family:monospace;">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;
  &lt;head&gt;
    &lt;?php include_http_metas() ?&gt;
    &lt;?php include_metas() ?&gt;
    &lt;title&gt;Facebook App&lt;/title&gt;
    &lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;style&gt;
      div.section {
        margin-bottom: 10px;
        background: #EEEEEE;
        padding: 5px 10px;
      }
      body {
        font-family: Arial;
        font-size: 12px;
      }
      pre {
        font-size: 10px;
        color: #333333;
        margin-left: 50px;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
    &lt;script src=&quot;http://connect.facebook.net/en_US/all.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
    FB.init({
       appId  : '&lt;?php echo sfConfig::get('app_facebook_app_id') ?&gt;',
       status : true, // vérifie le status de la connection
       cookie : true, // autorise les cookies pour permettre au serveur d'accéder à la session'
       xfbml  : true  // active le parsing de XFBML
      });
    &lt;/script&gt;
    ...</pre></td></tr></table></div>

<p>Nous en profitons pour charger JQuery afin de faciliter l&#8217;ajax et le remaniement du Dom.</p>
<p>Voilà, nous sommes prêts à attaquer les actions.</p>
<p>La première action va être l&#8217;authentification de l&#8217;utilisateur Facebook, et la gestion des permissions que celui-ci devra accorder à notre application.<br />
Le nouveau modèle de Facebook veut que nous demandions à l&#8217;utilisateur, dès le premier accès à l&#8217;application, qu&#8217;il accepte simultanément toutes les permissions nécessaires. Pour plus d&#8217;informations à ce sujet, consultez la liste des permissions sur <a href="http://developers.facebook.com/docs/authentication/permissions" target="_blank">le wiki Facebook Developer</a>.<br />
Voici l&#8217;action Login, qui sera appelée lorsque l&#8217;utilisateur n&#8217;a pas accordé ces permissions, ou lors d&#8217;une première visite de l&#8217;application:</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('p1187code37'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118737"><td class="code" id="p1187code37"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//apps/frontend/modules/demo/actions/actions.class.php</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeLogin<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//on génère l'url qui permettra le login à l'application</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLoginUrl</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'canvas'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'fbconnect'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
            <span style="color: #666666; font-style: italic;">//ici on demande les permissions email, publication sur le mur, et changement du status</span>
            <span style="color: #0000ff;">'req_perms'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'email,publish_stream,status_update'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'next'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</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>Comme nous sommes dans une application iframe, il faut charger l&#8217;url de login depuis la frame parente, et notre template va s&#8217;en charger:</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('p1187code38'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118738"><td class="code" id="p1187code38"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span>loginSuccess<span style="color: #339933;">.</span>php<span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
top<span style="color: #339933;">.</span>location<span style="color: #339933;">.</span>href <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;?php echo <span style="color: #006699; font-weight: bold;">$sf_data-&gt;getRaw</span>('loginUrl') ?&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Il faut maintenant que notre index redirige vers ce login dans les cas précédemment cités:</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('p1187code39'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118739"><td class="code" id="p1187code39"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//apps/frontend/modules/demo/actions/actions.class.php</span>
<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: #666666; font-style: italic;">//on vérifie si l'utilisateur a une session facebook active</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//sinon il doit s'identifier</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;">'demo/login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//s'il a une session active, on vérifie si elle est valide pour notre application</span>
    try
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</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;">;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fbme</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/me'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    catch <span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//sinon il doit à nouveau s'identifier</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;">'demo/login'</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>On peut maintenant voir une demande de permissions s&#8217;afficher lorsque l&#8217;on se connecte à l&#8217;application:<br />
<a href="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/perms.png"><img class="alignnone size-medium wp-image-1189" title="perms" src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/perms-300x172.png" alt="" width="300" height="172" /></a></p>
<p>En vérifiant la validité de la session, nous avons récupéré toutes les informations sur l&#8217;utilisateur auxquelles nos permissions nous donnent accès. Voyons l&#8217;étendue de ces informations en les affichant dans notre vue:</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('p1187code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118740"><td class="code" id="p1187code40"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> indexSuccess<span style="color: #339933;">.</span>php <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;section&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span>Informations utilisateur<span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>pre<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fbme</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #339933;">/</span>pre<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><a href="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/infos.png"><img class="alignnone size-medium wp-image-1195" title="infos" src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/infos-300x174.png" alt="" width="300" height="174" /></a><br />
Nous accédons bien à l&#8217;adresse email comme spécifié, ainsi qu&#8217;aux informations génériques et publiques sur l&#8217;utilisateur.</p>
<p>Il est maintenant temps d&#8217;interagir avec l&#8217;utilisateur. Il nous a également accordé l&#8217;accès à son status, nous allons donc lui proposer de l&#8217;éditer via notre application:</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('p1187code41'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118741"><td class="code" id="p1187code41"><pre class="html" style="font-family:monospace;">&lt;!-- indexSuccess.php --&gt;
...
&lt;div class=&quot;section&quot;&gt;
  &lt;a onclick=&quot;updateStatus();return false;&quot; href=&quot;#&quot;&gt;Changer mon status via Ajax et l'API PHP&lt;/a&gt;
  &lt;textarea id=&quot;status_text&quot; cols=&quot;40&quot; rows=&quot;2&quot;&gt;  &lt;/textarea&gt;
&lt;/div&gt;
...
&lt;script type=&quot;text/javascript&quot;&gt;
function updateStatus()
  {
    var status = document.getElementById('status_text').value;
&nbsp;
    $.ajax({
      type: 'post',
      url: '&lt;?php echo url_for('demo/statusUpdate') ?&gt;',
      data: 'status=' + status,
      success: function(response) {
        alert(response);
      },
      error: function(response) {
        alert(response);
      }
    });
  }
&lt;/script&gt;</pre></td></tr></table></div>

<p>La méthode js &laquo;&nbsp;updateStatus()&nbsp;&raquo; va faire un appel ajax à une nouvelle action updateStatus de notre application:</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('p1187code42'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118742"><td class="code" id="p1187code42"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//apps/frontend/modules/demo/actions/actions.class.php</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeUpdateStatus<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;">forward404Unless</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isXmlHttpRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$status</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;">'status'</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;">//un simple appel a l'api suffit à poster un nouveau status sur le profile de l'utilisateur</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span>
          <span style="color: #0000ff;">'/me/feed'</span><span style="color: #339933;">,</span>
          <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span>
          <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    catch <span style="color: #009900;">&#40;</span>FacebookApiException <span style="color: #000088;">$e</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;">renderText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Erreur: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$e</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Status mis-à-jour'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>L&#8217;api Javascript est toute aussi simple à utiliser. Proposons cette fois à l&#8217;utilisateur de parler de notre application sur son mur à l&#8217;aide de javascript:</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('p1187code43'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118743"><td class="code" id="p1187code43"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> indexSuccess<span style="color: #339933;">.</span>php <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">...</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;section&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;publishWall();return false;&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Poster un article sur mon mur via l<span style="color: #0000ff;">'API Javascript&lt;/a&gt;
&lt;/div&gt;
...
&lt;script type=&quot;text/javascript&quot;&gt;
function publishWall()
  {
    FB.ui(
    {
      method: '</span>stream<span style="color: #339933;">.</span>publish<span style="color: #0000ff;">',
      message: '</span><span style="color: #0000ff;">',
      attachment:
      {
        name: &quot;Démo Symfony+Facebook&quot;,
        caption: '</span><span style="color: #0000ff;">',
        description: &quot;Une démo simple d'</span>application Facebook avec Symfony et les dernières API Javascript et PHP de Facebook<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;,
        href: &quot;</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.lexik.fr/blog/symfony/non-classe/exemple-dapplication-utilisant-la-graph-api-de-facebook-1187&quot;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      user_prompt_message<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Application de démo Symfony+Facebook&quot;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Le résultat obtenu en cliquant sur le lien est le pseudo-popup bien connu de Facebook:<br />
<a href="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/publish.png"><img class="alignnone size-medium wp-image-1190" title="publish" src="http://www.lexik.fr/blog/symfony/wp-content/uploads/2010/07/publish-300x129.png" alt="" width="300" height="129" /></a></p>
<p>Nous venons de voir quelques méthodes simples d&#8217;accès ou de publication de données. Une liste plus complète des méthodes éxistantes est sur <a href="http://developers.facebook.com/docs/reference/rest/" target="_blank">le wiki Facebook Developer</a>.<br />
Dans le cadre d&#8217;applications plus complexes, il sera souvent utile de pouvoir formuler précisément les informations que l&#8217;on souhaite récupérer, et celles-ci ne correspondront pas nécessairement à une méthode éxistante. Pour cela Facebook met à notre disposition FQL, un langage de requète similaire à SQL dans sa syntaxe, pour générer nos requètes spécifiques.</p>
<p>Par exemple, récupérons la liste des amis de l&#8217;utilisateur avec leur nom, leur uid, et leur photo. Voici la requète FQL pour cela, et son éxécution via l&#8217;api 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('p1187code44'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118744"><td class="code" id="p1187code44"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//apps/frontend/modules/demo/actions/actions.class.php</span>
<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: #339933;">...</span>
    <span style="color: #666666; font-style: italic;">//récupération des amis via FQL</span>
    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT name, uid, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">amis</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">facebook</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'method'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fql.query'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'query'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$query</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'callback'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</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>Et l&#8217;affichage de la liste dans la vue:</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('p1187code45'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p118745"><td class="code" id="p1187code45"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> indexSuccess<span style="color: #339933;">.</span>php <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;section&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span>Liste d<span style="color: #0000ff;">'amis&lt;/h3&gt;
&lt;?php foreach ($amis as $ami): ?&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;img src=&quot;&lt;?php echo $ami['</span>pic_square<span style="color: #0000ff;">'] ?&gt;&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;?php echo $ami ['</span>name<span style="color: #0000ff;">'] ?&gt;&lt;/strong&gt;&lt;/li&gt;
	&lt;li&gt;uid: &lt;?php echo $ami['</span>uid<span style="color: #0000ff;">'] ?&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;?php endforeach; ?&gt;
&lt;/div&gt;</span></pre></td></tr></table></div>

<p>Cet article n&#8217;était pas dédié à Symfony, mais l&#8217;utilisait plutôt pour proposer un environnement familier à notre application. Ce survol rapide de la nouvelle Graph Api permet surtout de donner un point de départ sur l&#8217;utilisation de la nouvelle librairie à un moment ou la documentation à son sujet n&#8217;est pas vraiment fournie, en particulier en français !<br />
Vous pouvez voir l&#8217;application tourner sur <a href="http://apps.facebook.com/demoLexik" target="_blank">http://apps.facebook.com/demoLexik</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/exemple-dapplication-utilisant-la-graph-api-de-facebook-1187/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

