<?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>tbergeron-&#62;myHeadInsideOut(); &#187; php</title>
	<atom:link href="http://tbergeron.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://tbergeron.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 06:19:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Traitement du dernier élément d&#8217;un foreach [PHP]</title>
		<link>http://tbergeron.com/technologie/traitement-du-dernier-element-dun-foreach-php/</link>
		<comments>http://tbergeron.com/technologie/traitement-du-dernier-element-dun-foreach-php/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 15:42:06 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Technologie]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://tbergeron.com/?p=1171</guid>
		<description><![CDATA[Finalement! J&#8217;ai découvert une façon de faire un traitement différent sur le dernier élément d&#8217;un foreach! Si vous vous demandez l&#8217;utilité et bien, si vous programmez bien-sûre: ça vous a surement déjà arrivé de devoir faire un menu du genre: Accueil &#124; Dossiers &#124; À Propos Dans un foreach normal sa donnerais un « Accueil [...]]]></description>
			<content:encoded><![CDATA[<p>Finalement! J&#8217;ai découvert une façon de faire un traitement différent sur le dernier élément d&#8217;un foreach!</p>
<p>Si vous vous demandez l&#8217;utilité et bien, si vous programmez bien-sûre: ça vous a surement déjà arrivé de devoir faire un menu du genre:<br />
Accueil | Dossiers | À Propos</p>
<p>Dans un foreach normal sa donnerais un « Accueil | Dossiers | À Propos | » (un | de trop). Et comme vous le savez sûrement c&#8217;est bien difficile en PHP de détecter si l&#8217;élément sélectionné d&#8217;un foreach est le dernier.</p>
<p>Et bien voici la solution!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$numeros</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dernier</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$numeros</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$numeros</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$numero</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Je vérifie si le clé de l'element courant est</span>
	<span style="color: #666666; font-style: italic;">//la même que la clé du dernier élément.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span> <span style="color: #339933;">==</span><span style="color: #000088;">$dernier</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;le dernier!&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;les autres.&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Des heures de grattage de tête&#8230; en moins!</p>
]]></content:encoded>
			<wfw:commentRss>http://tbergeron.com/technologie/traitement-du-dernier-element-dun-foreach-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Supporter des structure de données parents/enfants</title>
		<link>http://tbergeron.com/technologie/supporter-des-structure-de-donnees-parentsenfants/</link>
		<comments>http://tbergeron.com/technologie/supporter-des-structure-de-donnees-parentsenfants/#comments</comments>
		<pubDate>Fri, 01 May 2009 17:21:12 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Technologie]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[enfants]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[parents]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[relations]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://tbergeron.com/?p=774</guid>
		<description><![CDATA[Aujourd&#8217;hui les enfants je vais vous montrer comment généré une liste avec des enfants à l&#8217;infinie. Dans la base de donnée, nous avons ce style de donnée: ID PARENT_ID TEXT 1 0 test 2 1 sous-test 3 0 nouveau test 4 2 sous-sous-test 5 1 sous-test 2 Comme vous pouvez voir, la structure est très [...]]]></description>
			<content:encoded><![CDATA[<p>Aujourd&#8217;hui les enfants je vais vous montrer comment généré une liste avec des enfants à l&#8217;infinie.</p>
<p>Dans la base de donnée, nous avons ce style de donnée:</p>
<pre>ID	PARENT_ID	TEXT
1	0		test
2	1		sous-test
3	0		nouveau test
4	2		sous-sous-test
5	1		sous-test 2
</pre>
<p>Comme vous pouvez voir, la structure est très simple. Nous avons nos entrées avec leurs titres, et dans la colonne PARENT_ID nous avons  les références qui pointent sur leurs parents.</p>
<p>Un fois généré la structure HTML ressemblera à ceci:</p>
<ul>
<li>test</li>
<li>
<ul>
<li>sous-test</li>
<li>
<ul>
<li>sous-sous-test</li>
</ul>
</li>
<li>sous-test 2</li>
</ul>
</li>
<li>nouveau test</li>
</ul>
<p>Alors, allons-y! Vous remarquerez évidement que comme à l&#8217;habitude j&#8217;utilise symfony comme framework.</p>
<p><strong>NB:</strong> Il est bien facile à voir que j&#8217;utilise Propel pour rejoindre et manipuler ma base de donnée. Si vous utilisez tout simplement des requêtes MySQL <em>hardcodé</em> vous pouvez <em>traduire</em> mon code à votre aise!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Je vais chercher tout les donnée que ma db contient:</span>
<span style="color: #000088;">$todo</span> <span style="color: #339933;">=</span> TodoPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Ensuite je créer des arrays qui contiendront l'arborescence de mes données</span>
<span style="color: #000088;">$refs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Je fais passé les résultats de ma requête dans un foreach qui compilera mon array</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$todo</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//J'entre les premières données dans l'array</span>
	<span style="color: #000088;">$thisref</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$refs</span>[ <span style="color: #006699; font-weight: bold;">$data-&gt;getId</span>() ];
	<span style="color: #006699; font-weight: bold;">$thisref</span>['parent_id'] = <span style="color: #006699; font-weight: bold;">$data-&gt;getParentId</span>();
	<span style="color: #006699; font-weight: bold;">$thisref</span>['name'] = <span style="color: #006699; font-weight: bold;">$data-&gt;getTitle</span>();
	//Je vérifie si l'entrée a des enfants.
	if (<span style="color: #006699; font-weight: bold;">$data-&gt;getParentId</span>() == 0) {
		//Si non j'entre l'entrée au premier niveau.
		<span style="color: #006699; font-weight: bold;">$list</span>[ <span style="color: #006699; font-weight: bold;">$data-&gt;getId</span>() ] = &quot;</span><span style="color: #000088;">$thisref</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Si oui je crée l'enfant dans un nouveau niveau.</span>
		<span style="color: #000088;">$refs</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParentId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'children'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$thisref</span>;
	}
}</span></pre></div></div>

<p>Vous remarquerez que le code utilisé est très court et rapide. Cela empêche l&#8217;utilisation de milliers de requêtes!</p>
<p>Et maintenant pour afficher correctement l&#8217;arborescence vous aurez besoin de cette fonction.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> generate_tree<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Ouverture du premier ul.</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Boucle récursive qui créera les prochains ul.</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Ajout d'un entré au même niveau.</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Si un enfant existe, on rappel la même fonction récursivement</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'children'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">.</span>toUL<span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'children'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//On ferme le ul initial!</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Et on renvoie le contenu</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>C&#8217;est ce qui conclut ce léger tutorial qui avait pour but de vous rendre la tâche facile avec ces structures de données qui sont habituellement bien difficile a manipuler.</p>
]]></content:encoded>
			<wfw:commentRss>http://tbergeron.com/technologie/supporter-des-structure-de-donnees-parentsenfants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update!</title>
		<link>http://tbergeron.com/blog/update/</link>
		<comments>http://tbergeron.com/blog/update/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 14:28:59 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://tbergeron.com/?p=611</guid>
		<description><![CDATA[Voici ce qu&#8217;il se passe dans ma vie c&#8217;est temps-ci: Utilisation massive du framework PHP Symfony. Découverte de GIT (version management), ça torche svn. solide! Création d&#8217;un système de blog que j&#8217;avance très très rapidement fait avec symfony, et publié sur github. Voici quelques screenshots: En deux jour, j&#8217;ai beaucoup avancer, vous pouvez voir le [...]]]></description>
			<content:encoded><![CDATA[<p>Voici ce qu&#8217;il se passe dans ma vie c&#8217;est temps-ci:</p>
<ol>
<li>Utilisation massive du framework PHP <a href="http://www.symfony-project.org/">Symfony</a>.</li>
<li>Découverte de <a href="http://git-scm.com/">GIT</a> (version management), ça torche <a href="http://subversion.tigris.org/">svn</a>. solide!</li>
<li>Création d&#8217;un système de blog que j&#8217;avance très très rapidement fait avec symfony, et <a href="http://github.com/tbergeron/blog/tree/master">publié</a> sur <a href="http://github.com">github</a>.</li>
</ol>
<p>Voici quelques screenshots:</p>

<a href='http://tbergeron.com/wp-content/uploads/2009/04/picture-1.png' rel='shadowbox[album-611];player=img;' title='picture-1'><img width="150" height="150" src="http://tbergeron.com/wp-content/uploads/2009/04/picture-1-150x150.png" class="attachment-thumbnail" alt="picture-1" title="picture-1" /></a>
<a href='http://tbergeron.com/wp-content/uploads/2009/04/picture-3.png' rel='shadowbox[album-611];player=img;' title='picture-3'><img width="150" height="150" src="http://tbergeron.com/wp-content/uploads/2009/04/picture-3-150x150.png" class="attachment-thumbnail" alt="picture-3" title="picture-3" /></a>
<a href='http://tbergeron.com/wp-content/uploads/2009/04/picture-4.png' rel='shadowbox[album-611];player=img;' title='picture-4'><img width="150" height="150" src="http://tbergeron.com/wp-content/uploads/2009/04/picture-4-150x150.png" class="attachment-thumbnail" alt="picture-4" title="picture-4" /></a>
<a href='http://tbergeron.com/wp-content/uploads/2009/04/picture-5.png' rel='shadowbox[album-611];player=img;' title='picture-5'><img width="150" height="150" src="http://tbergeron.com/wp-content/uploads/2009/04/picture-5-150x150.png" class="attachment-thumbnail" alt="picture-5" title="picture-5" /></a>
<a href='http://tbergeron.com/wp-content/uploads/2009/04/a.png' rel='shadowbox[album-611];player=img;' title='a'><img width="150" height="150" src="http://tbergeron.com/wp-content/uploads/2009/04/a-150x150.png" class="attachment-thumbnail" alt="a" title="a" /></a>

<p>En deux jour, j&#8217;ai beaucoup avancer, vous pouvez voir le code sur mon repo github. Je suis entrain de terminer la gestion des articles et ensuite je l&#8217;utiliserai pour un techblog perso à l&#8217;adresse <a href="http://pousli.net/blog">http://pousli.net/blog</a></p>
<p>Mon but n&#8217;est pas de réinventé la roue, mais bien de créer un système versatile, et bien reprogrammable. Je me fou de la gestion des plugins car tout sera programmé quand j&#8217;en aurai envie et dans l&#8217;ordre que je veux. Une semaine ce sera un système de commentaire, l&#8217;autre ce sera un système de gestion de medias, etc. Un beau petit challenge qui est entre autre un bon passe temps.</p>
<p>Apart çà, et bien ça va toujours bien avec ma femme, au bureau aussi et pas mal partout héhé. La vie quand c&#8217;est bien balancé et organisé ça rock en modit. Moi qui croyait que de vivre tout croche c&#8217;était cool&#8230; c&#8217;est encore plus cool de savoir qu&#8217;ont est bien entouré et que je serai encore vivant demain matin&#8230; Héhé. Tsé c&#8217;est le fun faire le hors la loi, mais tsé les lois ça peut-être été inventé pour justement&#8230; vivre? <img src='http://tbergeron.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Keep on rocking in a free world!</p>
]]></content:encoded>
			<wfw:commentRss>http://tbergeron.com/blog/update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dernieres , decouvertes&#8230;</title>
		<link>http://tbergeron.com/blog/dernieres-decouvertes/</link>
		<comments>http://tbergeron.com/blog/dernieres-decouvertes/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 00:36:41 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[battlegrounds]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[laptop]]></category>
		<category><![CDATA[level]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wow]]></category>

		<guid isPermaLink="false">http://tbergeron.com/2009/01/dernieres-decouvertes/</guid>
		<description><![CDATA[Hey bande de pokailles! Voici mes derniers &#171;&#160;kicks&#160;&#187; et aquisitions: WoW Battlegrounds, c&#8217;est trop nice c&#8217;est comme unreal tournement mais avec ton toon de WoW!!! Nouveau Disquedur 2.5 320gb 16mb 7200, enfin de l&#8217;espace sur mon laptop! CodeIgniter (framework PHP), recommandation d&#8217;hubert (lepetitweb) qui m&#8217;a l&#8217;air vraiment fort!!! Jcommence a developper un peu avec, mais [...]]]></description>
			<content:encoded><![CDATA[<p>Hey bande de pokailles!</p>
<p>Voici mes derniers &laquo;&nbsp;kicks&nbsp;&raquo; et aquisitions:</p>
<ol>
<li>WoW Battlegrounds, c&#8217;est trop nice c&#8217;est comme unreal tournement mais avec ton toon de WoW!!!</li>
<li>Nouveau Disquedur 2.5 320gb 16mb 7200, enfin de l&#8217;espace sur mon laptop!</li>
<li>CodeIgniter (framework PHP), recommandation d&#8217;hubert (lepetitweb) qui m&#8217;a l&#8217;air vraiment fort!!! Jcommence a developper un peu avec, mais a date je crois que j&#8217;adopterai!</li>
</ol>
<p>C&#8217;est tout pour le moment, mon toon est rendu lvl 30!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://tbergeron.com/blog/dernieres-decouvertes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
