<?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; javascript</title>
	<atom:link href="http://www.lexik.fr/blog/symfony/tag/javascript/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>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>Astuces de développement javascript avec symfony</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/astuces-de-developpement-javascript-avec-symfony-1382</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/astuces-de-developpement-javascript-avec-symfony-1382#comments</comments>
		<pubDate>Mon, 17 Jan 2011 15:06:09 +0000</pubDate>
		<dc:creator>jeremy</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.lexik.fr/blog/symfony/?p=1382</guid>
		<description><![CDATA[Dans cet article nous allons voir quelques astuces et bonnes pratiques, non pas directement de développement symfony mais de développement javascript au sein d’un projet symfony. Si l&#8217;on reprend quelques bases de bonnes pratiques de développement javascript, on constate : &#8230;<p class="more aright"><a href="http://www.lexik.fr/blog/symfony/symfony/astuces-de-developpement-javascript-avec-symfony-1382">...</a></p>]]></description>
			<content:encoded><![CDATA[<p>Dans cet article nous allons voir quelques astuces et bonnes pratiques, non pas directement de développement symfony mais de développement javascript au sein d’un projet symfony.</p>
<p>Si l&#8217;on reprend quelques bases de bonnes pratiques de développement javascript, on constate :</p>
<ul>
<li>que vos javascripts doivent être non-intrusifs, autrement dit là pour améliorer l&#8217;expérience utilisateur et en aucun cas être indispensable au fonctionnement d&#8217;une page ;</li>
<li>que les javascript doivent être combinés en 1 seul fichier et minifié (ceci afin de limiter le nombre de requête HTTP et car le chargement de la page est arrêté à chaque balise script, notamment à cause d&#8217;un éventuel <code>document.write();</code> ;</li>
<li>que l&#8217;appel au javascript doit être en bas de page ;</li>
</ul>
<p><em>Cette liste est bien entendu non exhaustive, vous trouverez une <a href="http://developer.yahoo.com/performance/rules.html" target="_blank">liste plus détaillée par ici</a>.</em></p>
<p>Toutes ces bonnes pratiques de développement Javascript n’ont pas toujours été facilitées dans symfony, notamment à la grande époque des helpers link_to_remote() &#038; co. qui en ont ravi certains et fait cauchemarder d’autres. Et aujourd&#8217;hui encore bon nombre de widgets de formulaire retournent directement du code javascript (dépendant de jQuery ou autre) et qui ne fonctionneront évidemment plus dès lors que vos javascripts se trouveront en bas de page.</p>
<p><span id="more-1382"></span></p>
<h4>1. Où placer les javascripts dans le document</h4>
<p>Idéalement et selon les recommandations de Yslow, en bas de page, donc juste avant la balise fermante <code><body></code> de votre layout.php. Ceci afin de ne pas ralentir inutilement le début du chargement de votre page, puisque chaque balise script bloque le chargement de la page (notamment pour gérer le <code>document.write();</code>).<br />
Source : <a href="http://developer.yahoo.com/performance/rules.html#js_bottom" target="_blank">http://developer.yahoo.com/performance/rules.html#js_bottom</a></p>
<p>Si cette méthode ne vous gênera pas pour les librairies tierces telles que jQuery, qu&#8217;en est-il par contre de vos codes javascript ? Ils doivent également se trouver dans des fichiers séparés, dissociés de votre document HTML. Néanmoins comme je vois souvent le besoin pour les développeurs d&#8217;avoir le code javascript au sein du template symfony, voici une technique pour qu&#8217;il soit tout de même placé en fin de page : via un slot.</p>
<p>Un petit exemple de code :</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('p1382code18'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p138218"><td class="code" id="p1382code18"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// indexSuccess.php :</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> slot<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&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>
  console<span style="color: #339933;">.</span><a href="http://www.php.net/log"><span style="color: #990000;">log</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript @ bottom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> end_slot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// layout.php :</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> include_javascripts<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;">&lt;?php</span> include_slot<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Vous pourrez ainsi éditer votre code javascript depuis votre template PHP, bénéficier par exemple de valeurs dynamiques de PHP et pour autant que le code soit bien inclus en bas de page. Toutefois je vous recommande d&#8217;écrire du javascript là où il doit se trouver, à savoir dans un fichier JS&#8230;</p>
<p>De plus l&#8217;inconvénient majeur du slot est qu&#8217;il ne peut contenir qu&#8217;une valeur, il est écrasé à chaque utilisation. La technique fonctionne mais est très limitée. Pour ces besoins nous avons écrit chez Lexik un petit plugin &laquo;&nbsp;lxJavascript&nbsp;&raquo;, très similaire à l&#8217;utilisation d&#8217;un slot mais optimisé pour l&#8217;inclusion de javascripts. Il gère donc le multiple ajout, supprime les éventuelles multiples balises script pour en conserver qu&#8217;une seule, etc. Vous en saurez plus demain, le plugin sort en OpenSource sur le <a href="https://github.com/lexik" target="_blank">Github de Lexik</a>.</p>
<h4>2. Compression</h4>
<p>La compression des javascripts (c&#8217;est valable aussi pour les CSS) est une des tâches d&#8217;optimisations les plus importantes et également une des plus simples, du moins via les plugins symfony. Cette technique consiste à compresser tous vos fichiers javascript en 1 seul et surtout d&#8217;y appliquer un numéro de version (un timestamp le plus souvent) afin de prévenir des problèmes de cache dans vos mises à jour.</p>
<p>Les principaux plugins :</p>
<ul>
<li><a href="http://www.symfony-project.org/plugins/sfCombinePlugin" target="_blank">sfCombinePlugin</a>
<li><a href="http://www.symfony-project.org/plugins/npAssetsOptimizerPlugin" target="_blank">npAssetsOptimizerPlugin</a></li>
<li><a href="http://www.symfony-project.org/plugins/swCombinePlugin" target="_blank">swCombinePlugin</a></li>
</ul>
<p>Chez Lexik, nous utilisons <a href="http://www.symfony-project.org/plugins/npAssetsOptimizerPlugin" target="_blank">npAssetsOptimizerPlugin</a>, un plugin de <a href="http://www.akei.com/" target="_blank">Nicolas Perriault</a>, extrêmement simple à installer et paramétrer. Sur votre environnement de production, vous obtiendrez ainsi un fichier javascript compressé <code>/js/optimized.js?1294759429</code> qui contient un timestamp permettant à chaque modifications des fichiers d&#8217;être prises en compte sans problème de cache.</p>
<p>Nous n&#8217;appliquons pas la compression pour les librairies externes telles que jQuery que nous déléguons aux <a href="http://code.google.com/apis/libraries/devguide.html" target="_blank">serveurs CDN de Google</a>, cela apporte ces avantages notables :</p>
<ul>
<li>l&#8217;avantage du <abbr title="Content Delivery Network">CDN</abbr>, à savoir de proposer des données statiques via un réseau de multiples serveurs dans de multiples points géographiques, afin de permettre un accès très court ;</li>
<li>les navigateurs sont limités sur le nombre de connexions HTTP simultanées sur un même domaine, le téléchargement d&#8217;un javascript sur les serveurs de Google se fera en parallèle ;</li>
<li>les librairies du CDN ont les bonnes en-têtes de cache, par exemple la version 1.4.4 de jQuery restera en cache pendant 1 an sur le client, cela signifie également qu&#8217;un internaute peut bénéficier du cache téléchargé depuis un autre site, pas forcément sur le votre.</li>
</ul>
<h4>3. Accéder à certaines données dynamiques depuis javascript</h4>
<p>Il peut parfois être très utile depuis javascript d&#8217;accéder à certaines données dynamiques telles que la culture de l&#8217;utilisateur, du routing pour des appels Ajax ou encore de l&#8217;i18n. Il suffit de s&#8217;appuyer sur un simple fichier de configuration via un tableau de données JSON généré depuis une action symfony. J&#8217;ai écrit sur mon blog personnel un article détaillé sur le sujet <a href="http://blog.jeremybarthe.com/post/1465024153/configurations-javascript-dynamiques-en-symfony" target="_blank">Configurations Javascript dynamiques en Symfony</a>.</p>
<h4>4. Javascript depuis les widget</h4>
<p>Maintenant que vos inclusions de javascripts se trouvent en bas de page, jQuery par exemple, que faire de nos chers widgets jQuery Autocompleter <code>sfWidgetFormJQueryAutocompleter</code> et autre Datepicker <code>sfWidgetFormJQueryDate</code> qui retournent des champs de formulaire et le javascript d’initialisation du composant ? Eh bien, ne plus les utiliser&#8230; Simplement car ils seront inclus avant jQuery et vous aurez donc droit à l’erreur &laquo;&nbsp;jQuery is not defined&nbsp;&raquo;. Sans être aussi extrême, vous pouvez charger jQuery en haut de page (via les CDN de Google) et votre script compressé en bas de page, les widgets de formulaire seront alors à nouveau fonctionnels.</p>
<p>Cela fait déjà quelques temps que chez Lexik nous avons fait le choix d&#8217;enlever tous ces widgets pour les ré-écrire et les adapter à nos besoins. Les javascripts des widgets passent par notre plugin lxJavascript ce qui permet de les inclure là où on le souhaite. Egalement, le javascript retourné par ces widgets correspond à une utilisation basique du composant, dans un cas concrêt il est souvent nécessaire d&#8217;en ré-écrire une bonne part. Il peut être pratique par contre que le widget retourne seulement la sémantique HTML adaptée, par exemple dans le cas d&#8217;un Autocomplete un champ hidden pour stocker la valeur et un champ texte pour l&#8217;autocomplete, aussi nos widgets ont une option pour retourner ou non le code javascript.</p>
<h4>5. Optimisation frontend</h4>
<p>Presque aussi important que la compression, la configuration d&#8217;apache pour mettre en cache certains de vos fichiers statiques. Typiquement, maintenant que vos fichiers javascripts et CSS sont compressés en 1 seul et possèdent un timestamp unique par version, il serait dommage de les recharger à chaque chargement de page&#8230; Vous devez donc configurer le module Expires d&#8217;apache via le fichier de config du vhost ou via le .htaccess, en voici un exemple :</p>
<pre>
<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"
</IfModule>
</pre>
<p>Vos fichiers javascript et CSS seront ainsi en cache pendant 1 an, attention du coup à ne pas avoir de fichier sans numéro de version, car ils resteraient en cache et vos internautes ne bénéficieraient pas de vos mises à jour&#8230;</p>
<p>&nbsp;</p>
<p>Dernière chose, si ce n&#8217;est pas encore fait, installez et testez <a href="http://developer.yahoo.com/yslow/" target="_blank">Yslow</a> pour trouver des pistes d&#8217;optimisations de performance de vos sites.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/astuces-de-developpement-javascript-avec-symfony-1382/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Du Javascript dynamique dans une vue en utilisant sf_format</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746#comments</comments>
		<pubDate>Wed, 08 Jul 2009 07:13:32 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sf_format]]></category>
		<category><![CDATA[vue]]></category>

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

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code26'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74626"><td class="code" id="p746code26"><pre class="yml" style="font-family:monospace;">...
actu_index:
  url:   /actualites/index.:sf_format
  param: { module: actu, action: index, sf_format: html }
...</pre></td></tr></table></div>

<p>Dans notre action on récupère juste les dernières actualités à afficher dans la page html (/app/frontend/modules/actu/actions/actions.class.php).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74627"><td class="code" id="p746code27"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> actuActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">actus</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Actu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLast</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La vue Html. C&#8217;est la que ca se passe ! On fais un use_javascript() auquel on passe le url_for() de la même vue en spécifiant juste le sf_format à &#8216;js&#8217; (/app/frontend/modules/actu/templates/indexSuccess.php).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74628"><td class="code" id="p746code28"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span>url_for<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@actu_index?sf_format=js'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;liste_actus&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$actus</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$actu</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;actu&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$actu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTitre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$actu</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTexteCourt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;action&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Lire la suite'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'@actu_detail'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Et donc la vue js sera inclue par la vue html qui rajoute dans le head l&#8217;appel au fichier.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code29'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74629"><td class="code" id="p746code29"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;/actualites/index.js&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Il ne reste plus qu&#8217;a faire la script javascript dans la vue /app/frontend/modules/actu/templates/indexSuccess.js.php ou on peut avoir accès  à tous les éléments de symfony que l&#8217;on désire.</p>
<p>Par exemple là un peut appel ajax en jQuery ou je récupère l&#8217;url du script appelé grâce au routing.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code30'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74630"><td class="code" id="p746code30"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.action a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span>
      <span style="color: #3366CC;">'&lt;?php echo url_for('</span><span style="color: #339933;">@</span>actu_detail<span style="color: #3366CC;">') ?&gt;'</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #3366CC;">'script'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Il se peut que dans la vue javascript on n&#8217;ait pas besoin d&#8217;exécuter toute l&#8217;action.<br />
Par exemple ici, dans ma vue javascript, je n&#8217;ai pas besoin des dernières actualités, il est donc possible de filtrer pour alléger l&#8217;action grâce au sf_format.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code31'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74631"><td class="code" id="p746code31"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> actuActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_format'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">actus</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Actu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLast</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Après, libre a chacun de voir si on doit utiliser la même action que la vue html ou si la vue javascript nécessite sa propre action.</p>
<p>En utilisant une action séparée pour la vue javascript on peut s&#8217;amuser à pousser le vice du camouflage en utilisant un routing qui fasse croire que l&#8217;on appelle un fichier .js (Attention si jamais un fichier avec le même nom existe réellement dans le répertoire /web/js c&#8217;est ce dernier qui sera inclus).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code32'); return false;">View Code</a> YML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p74632"><td class="code" id="p746code32"><pre class="yml" style="font-family:monospace;">...
actu_index_js:
  url:   /js/actu.:sf_format
  param: { module: actu, action: index, sf_format: js }
...</pre></td></tr></table></div>

<p><b>Avantage de cette technique :</b></p>
<ul>
<li>Un code source html super &laquo;&nbsp;clean&nbsp;&raquo;</li>
</ul>
<p><b>Inconvéniant :</b></p>
<ul>
<li>Pour une page html, on fait deux appels à symfony.<br />
A utiliser avec parcimonie et bien optimiser les actions pour ne pas faire des requêtes inutiles sur la base de donnée.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lexik.fr/blog/symfony/symfony/du-javascript-dynamique-dans-une-vue-en-utilisant-sf_format-746/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TinyMCE dans l&#8217;admin generator (Symfony 1.2, Doctrine)</title>
		<link>http://www.lexik.fr/blog/symfony/symfony/sfformextraplugin-tinymce-197</link>
		<comments>http://www.lexik.fr/blog/symfony/symfony/sfformextraplugin-tinymce-197#comments</comments>
		<pubDate>Wed, 04 Mar 2009 22:58:26 +0000</pubDate>
		<dc:creator>Samuel Breton</dc:creator>
				<category><![CDATA[1.2.x]]></category>
		<category><![CDATA[Admingenerator 1.2.x]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rich text editor]]></category>
		<category><![CDATA[sfFormExtraPlugin]]></category>
		<category><![CDATA[tinyMCE]]></category>

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

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

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

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p197code38'); return false;">View Code</a> SF</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19738"><td class="code" id="p197code38"><pre class="sf" style="font-family:monospace;">symfony plugin:install sfFormExtraPlugin</pre></td></tr></table></div>

<h2>Modifier le widget sfWidgetFormTextareaTinyMCE.class.php</h2>
<p>Il faut modifier le plugin !</p>
<blockquote><p>/plugins/sfFormExtraPlugin/lib/widget/sfWidgetFormTextareaTinyMCE.class.php</p></blockquote>
<p>Fichier :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p197code39'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19739"><td class="code" id="p197code39"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> sfWidgetFormTextareaTinyMCE <span style="color: #000000; font-weight: bold;">extends</span> sfWidgetFormTextarea
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theme'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'advanced'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'config'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #339933;">...</span></pre></td></tr></table></div>

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

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p197code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19740"><td class="code" id="p197code40"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> ContenuForm <span style="color: #000000; font-weight: bold;">extends</span> BaseContenuForm
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'texte'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormTextareaTinyMCE<span style="color: #009900;">&#40;</span>
      <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'width'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">550</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'height'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">350</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'config'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'theme_advanced_disable: &quot;anchor,image,cleanup,help&quot;'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'theme'</span>   <span style="color: #339933;">=&gt;</span>  sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_tinymce_theme'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'advanced'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'class'</span>   <span style="color: #339933;">=&gt;</span>  <span style="color: #0000ff;">'tiny_mce'</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$js_path</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_rich_text_js_dir'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span>sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sf_rich_text_js_dir'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/tiny_mce.js'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'/sf/tinymce/js/tiny_mce.js'</span><span style="color: #339933;">;</span>
    sfContext<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addJavascript</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$js_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

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

