<?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/"
	>

<channel>
	<title>pasunclou</title>
	<atom:link href="http://www.pasunclou.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pasunclou.com</link>
	<description>tutoriaux et blog sur l'Open Source</description>
	<pubDate>Wed, 27 May 2009 12:15:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Vue avec CodeIgniter (partie 4)</title>
		<link>http://www.pasunclou.com/2009/05/27/vue-avec-codeigniter-partie-4/</link>
		<comments>http://www.pasunclou.com/2009/05/27/vue-avec-codeigniter-partie-4/#comments</comments>
		<pubDate>Wed, 27 May 2009 12:15:22 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[framework]]></category>

		<category><![CDATA[programmation]]></category>

		<category><![CDATA[codeigniter]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=913</guid>
		<description><![CDATA[Les vues permettent de séparer le fonctionnement de l&#8217;application avec le rendu final. Il est possible d&#8217;afficher les résultats directement depuis le model ou le controller mais celà est fortement déconseillé. Nous ne préservons plus la logique de séparation du modèle MVC.
Afin de mieux comprendre le bénéfice de l&#8217;architecture MVC nous allons dans un premier [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/04/16/modele-controlleur-codeigniter-partie-3/' rel='bookmark' title='Permanent Link: Modèle et contrôleur avec CodeIgniter (partie 3)'>Modèle et contrôleur avec CodeIgniter (partie 3)</a> <small>Dans la partie précédente nous avons vu comment se servir...</small></li><li><a href='http://www.pasunclou.com/2009/03/25/configurer-et-utiliser-la-base-de-donnees-avec-codeigniter-partie-2/' rel='bookmark' title='Permanent Link: Configurer et utiliser la base de données avec CodeIgniter (partie 2)'>Configurer et utiliser la base de données avec CodeIgniter (partie 2)</a> <small>Pour ce deuxième tutoriel, vous devez avoir installé CodeIgniter sur...</small></li><li><a href='http://www.pasunclou.com/2009/03/11/introduction-et-installation-de-codeigniter-partie-1/' rel='bookmark' title='Permanent Link: Introduction et installation de CodeIgniter (partie 1)'>Introduction et installation de CodeIgniter (partie 1)</a> <small>Introduction CodeIgniter est un framework PHP destiné à réduire votre...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Les vues permettent de séparer le fonctionnement de l&#8217;application avec le rendu final. Il est possible d&#8217;afficher les résultats directement depuis le model ou le controller mais celà est fortement déconseillé. Nous ne préservons plus la logique de séparation du modèle MVC.</p>
<p>Afin de mieux comprendre le bénéfice de l&#8217;architecture MVC nous allons dans un premier temps contrôller ce que nous allons disposer à l&#8217;écran par l&#8217;intermédiaire du contrôleur. Nous nous rendrons très vite compte que cette manière de faire est très difficile à maintenir.</p>
<p>Voici à quoi ressemblait notre contrôleur dans la partie précédente :</p>

<div class="wp_codebox"><table width="100%" ><tr id="p9139"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p913code9"><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> Users <span style="color: #000000; font-weight: bold;">extends</span> MY_Controller <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> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">// ...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Nous avons tous nos utilisateurs avec leur profil dans un tableau que nous avons nommé $data. Pour extraire ces données nous utiliserons la boucle foreach.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91310"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p913code10"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Articles_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$profil</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h1&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/h1&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Lieu : <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">city</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">country</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;What's your favorite colour ? <span style="color: #009933; font-weight: bold;">%s</span>&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">colours</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Le rendu est plutôt simple à agencer, mais le rendu est inacceptable, si nous devons avoir un header, un footer, peut-être une sidebar et ajouter des styles aux différents éléments, de plus qu&#8217;en adviendra-t-il lorsque nous aurons plusieurs rendu ?<br />
L&#8217;exercice est plutôt périlleux, cependant vous pouvez toujours vous exercez&#8230;</p>
<p>C&#8217;est ici qu&#8217;intervient ce que nous nommons la vue. Dans le contrôleur nous devons spécifier un template ainsi que les données à envoyer.</p>
<p>Ceci se fait par l&#8217;intermédiaire de :</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91311"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p913code11"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nom du template sans extension'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Notre méthode index() ressemblera alors à :</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91312"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p913code12"><pre class="php" style="font-family:monospace;">        <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Si vous essayez maintenant de voir le rendu à l&#8217;aide de votre navigateur, vous devriez apercevoir une erreur. Ce qui est normal car nous savons ce que nous faisons (non ?). Rendons-nous dans le répertoire views pour créer la vue home.php</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91313"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p913code13"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Les articles<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>Les articles du site<span style="color: #339933;">&lt;/</span>h1<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;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$profil</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h1&gt;<span style="color: #009933; font-weight: bold;">%s</span>&lt;/h1&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Lieu : <span style="color: #009933; font-weight: bold;">%s</span>, <span style="color: #009933; font-weight: bold;">%s</span>&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">city</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">country</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/printf"><span style="color: #990000;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;What's your favorite colour ? <span style="color: #009933; font-weight: bold;">%s</span>&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$profil</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">colours</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Cette fois nous avons créer, un fichier home.php ne contenant que la vue de notre application. Nous pouvons déjà apprécier le confort que peut apporter la séparation du model, du contrôleur et de la vue. Il est maintenant plus simple pour un designer d&#8217;opérer sur ce modèle, sans savoir ce qui se trame derrière.</p>
<p>CodeIgniter est fournie avec un parseur de base. Pour charger ce parseur, éditons le fichier application/config/autoload.php et ajoutons la librairie pour qu&#8217;elle se charge automatiquement.<br />
L&#8217;avantage du parseur est que nous pouvons utiliser un langage spécifique à l&#8217;intérieur de notre template.<br />
L&#8217;appel au sein de notre contrôleur se fera en rempla‎‎çant</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91314"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p913code14"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #339933;">,</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>par</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91315"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p913code15"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Nous pouvons alors maintenant accéder à nos données sous la forme {data}.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p91316"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p913code16"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Liste des utilisateurs<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span>Profil des utilisateurs<span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
    <span style="color: #009900;">&#123;</span>data<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span>username<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span>city<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>country<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span>colours<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span>data<span style="color: #009900;">&#125;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><code>{articles}...{/articles}</code> agit ici pour indiquer une boucle, tandis que {title}, {date} et {content} sont les éléments de notre objet.</p>
<p>L&#8217;utilisation d&#8217;un parseur n&#8217;est pas obligatoire. Elle dépend des envies et des attentes de chacun. Le parseur par défaut de CI n&#8217;offre pas beaucoup d&#8217;options et l&#8217;utilisation avancée d&#8217;un réel moteur de template vient à manquer rapidement. Smarty semble le candidat idéal, outre le fait de pouvoir manager simplement nos données facilement, il offre l&#8217;avantage de mixer les templates, choses assez compliqué à réaliser avec le moteur par défaut de codeigniter. De plus Smarty offre une panoplie d&#8217;outils pour aider à formater les données (majuscules, minuscules, échappement&#8230;) et une communauté assez forte.</p>
<p>Dans le prochain tutoriel nous intégrerons Smarty. Si vous ne le connaissez pas rendez-vous sur le <a href="http://www.smarty.net/">site officiel</a>. </p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/04/16/modele-controlleur-codeigniter-partie-3/' rel='bookmark' title='Permanent Link: Modèle et contrôleur avec CodeIgniter (partie 3)'>Modèle et contrôleur avec CodeIgniter (partie 3)</a> <small>Dans la partie précédente nous avons vu comment se servir...</small></li><li><a href='http://www.pasunclou.com/2009/03/25/configurer-et-utiliser-la-base-de-donnees-avec-codeigniter-partie-2/' rel='bookmark' title='Permanent Link: Configurer et utiliser la base de données avec CodeIgniter (partie 2)'>Configurer et utiliser la base de données avec CodeIgniter (partie 2)</a> <small>Pour ce deuxième tutoriel, vous devez avoir installé CodeIgniter sur...</small></li><li><a href='http://www.pasunclou.com/2009/03/11/introduction-et-installation-de-codeigniter-partie-1/' rel='bookmark' title='Permanent Link: Introduction et installation de CodeIgniter (partie 1)'>Introduction et installation de CodeIgniter (partie 1)</a> <small>Introduction CodeIgniter est un framework PHP destiné à réduire votre...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/05/27/vue-avec-codeigniter-partie-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hadopi adoptée&#8230; La France toujours en retard</title>
		<link>http://www.pasunclou.com/2009/05/13/hadopi-adoptee-la-france-toujours-en-retard/</link>
		<comments>http://www.pasunclou.com/2009/05/13/hadopi-adoptee-la-france-toujours-en-retard/#comments</comments>
		<pubDate>Wed, 13 May 2009 11:11:12 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[actualité]]></category>

		<category><![CDATA[Hadopi]]></category>

		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/2009/05/13/hadopi-adoptee-la-france-toujours-en-retard/</guid>
		<description><![CDATA[La loi HADOPI vient d&#8217;être adoptée. Une preuve de plus que le gouvernement de France ne sait pas réfléchir sur des questions modernes. Répression au lieu de réfléchir sur de nouvelles formes d&#8217;investissements du Web.
Les droits d&#8217;auteur, le copyright, le copyleft, l&#8217;Open Source en général ont été passé à la trape. La France dort et [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2008/09/02/google-a-toujours-le-sens-de-lhumour/' rel='bookmark' title='Permanent Link: Google a toujours le sens de l&#8217;humour'>Google a toujours le sens de l&#8217;humour</a> <small>Non seulement Google annonce Chrome (qui fait le buzz partout)...</small></li><li><a href='http://www.pasunclou.com/2009/02/27/black-out/' rel='bookmark' title='Permanent Link: Black-out'>Black-out</a> <small>Devant le ridicule d&#8217;un gouvernement qui s&#8217;entête à vouloir déconnecter...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>La loi HADOPI vient d&#8217;être adoptée. Une preuve de plus que le gouvernement de France ne sait pas réfléchir sur des questions modernes. Répression au lieu de réfléchir sur de nouvelles formes d&#8217;investissements du Web.</p>
<p>Les droits d&#8217;auteur, le copyright, le copyleft, l&#8217;Open Source en général ont été passé à la trape. La France dort et stagne et se laisse dicter par des partenariats avec entre hommes politiques et majors ayant des intérêts uniquement en France au détriment de la raison commune. Il n&#8217;y a que regarder les soutiens mobilisés par la <a href="http://www.laquadrature.net/HADOPI">quadrature du Web</a> ainsi qu&#8217;un échantillon des réactions à cette loi sur <a hreft="http://twitter.com/#search?q=hadopi">Twitter</a>.</p>
<p>Hier le fichier Edwig, aujourd&#8217;hui Hadopi et demain une taxe sur les base de données ? Freelance, entrepreneur, PME et utilisateurs du Web, les lois se moquent de nous !</p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2008/09/02/google-a-toujours-le-sens-de-lhumour/' rel='bookmark' title='Permanent Link: Google a toujours le sens de l&#8217;humour'>Google a toujours le sens de l&#8217;humour</a> <small>Non seulement Google annonce Chrome (qui fait le buzz partout)...</small></li><li><a href='http://www.pasunclou.com/2009/02/27/black-out/' rel='bookmark' title='Permanent Link: Black-out'>Black-out</a> <small>Devant le ridicule d&#8217;un gouvernement qui s&#8217;entête à vouloir déconnecter...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/05/13/hadopi-adoptee-la-france-toujours-en-retard/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installer Ruby on Rails sur Linux</title>
		<link>http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/</link>
		<comments>http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/#comments</comments>
		<pubDate>Sun, 10 May 2009 15:55:32 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[programmation]]></category>

		<category><![CDATA[tutoriaux]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[RoR]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=973</guid>
		<description><![CDATA[Voici quelques lignes de commandes pour installer Ruby on Rails sur Linux
Télécharger le dernier package de ruby (1.8.7) (suivre les recommandation ici, aujourd&#8217;hui il est recommandé de prendre ruby 1.8.7)

$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
$ tar -xvf ruby-1.8.7-p72.tar.gz
$ cd ruby-1.8.7-p72


Vérifier que ./configure est plus récent que configure.ini, sinon autoconf
./configure
make
make test
make install (en super user)
type ruby &#038;&#038; ruby -V [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li><li><a href='http://www.pasunclou.com/2009/05/09/chkrootkit-verifier-la-presene-de-rootkit-sur-v/' rel='bookmark' title='Permanent Link: chkrootkit : vérifier la présence de rootkit sur votre linux'>chkrootkit : vérifier la présence de rootkit sur votre linux</a> <small>chkrootkit est une application permettant de vérifier la présence de...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/' rel='bookmark' title='Permanent Link: Faire cohabiter plusieurs versions de Python'>Faire cohabiter plusieurs versions de Python</a> <small>Par défaut sur ma distribution de Linux Ubuntu 8.10 je...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Voici quelques lignes de commandes pour installer Ruby on Rails sur Linux</p>
<p>Télécharger le dernier package de ruby (1.8.7) (suivre les recommandation ici, aujourd&#8217;hui il est recommandé de prendre ruby 1.8.7)</p>
<pre>
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
$ tar -xvf ruby-1.8.7-p72.tar.gz
$ cd ruby-1.8.7-p72
</pre>
<ul>
<li>Vérifier que ./configure est plus récent que configure.ini, sinon autoconf</li>
<li>./configure</li>
<li>make</li>
<li>make test</li>
<li>make install (en super user)</li>
<li>type ruby &#038;&#038; ruby -V (pour savoir où est installer ruby et quelle version)</li>
</ul>
<p>Ensuite il faut récupérer RugyGems qui est le gestionnaire de paquet pour Ruby, plus d&#8217;informations sur le site de <a href="http://rubyforge.org/frs/?group_id=126">RubyForge</a>.</p>
<pre>
wget http://rubyforge.org/frs/download.php/56227/rubygems-1.3.3.tgz
tar -xvf rubygems-1.3.3.tgz
sudo ruby setup.rb
</pre>
<p>Maintenant nous pouvons passer par gems pour installer rails.</p>
<pre>
sudo gem install rails
</pre>
<p>Vous pouvez désormais suivre les tutoriaux du web comme les screencasts consultable sur le <a href="http://rubyonrails.org/screencasts">site officiel</a>.</p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li><li><a href='http://www.pasunclou.com/2009/05/09/chkrootkit-verifier-la-presene-de-rootkit-sur-v/' rel='bookmark' title='Permanent Link: chkrootkit : vérifier la présence de rootkit sur votre linux'>chkrootkit : vérifier la présence de rootkit sur votre linux</a> <small>chkrootkit est une application permettant de vérifier la présence de...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/' rel='bookmark' title='Permanent Link: Faire cohabiter plusieurs versions de Python'>Faire cohabiter plusieurs versions de Python</a> <small>Par défaut sur ma distribution de Linux Ubuntu 8.10 je...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>chkrootkit : vérifier la présence de rootkit sur votre linux</title>
		<link>http://www.pasunclou.com/2009/05/09/chkrootkit-verifier-la-presene-de-rootkit-sur-v/</link>
		<comments>http://www.pasunclou.com/2009/05/09/chkrootkit-verifier-la-presene-de-rootkit-sur-v/#comments</comments>
		<pubDate>Sat, 09 May 2009 18:49:01 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[tutoriaux]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=971</guid>
		<description><![CDATA[chkrootkit est une application permettant de vérifier la présence de rootkit sur votre linux. Un rootkit est un programme permettant de garder une porte ouverte sur votre système. Ce qui est généralement utilisé par les pirates.
Garder une porte secrète peut servir à diverses choses. Le pirate peut avoir un besoin d&#8217;un service sur votre machine [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/' rel='bookmark' title='Permanent Link: Installer Ruby on Rails sur Linux'>Installer Ruby on Rails sur Linux</a> <small>Voici quelques lignes de commandes pour installer Ruby on Rails...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li><li><a href='http://www.pasunclou.com/2008/09/05/des-astuces-pour-securiser-votre-wordpress/' rel='bookmark' title='Permanent Link: Des astuces pour sécuriser votre Wordpress'>Des astuces pour sécuriser votre Wordpress</a> <small> Nous ne sommes jamais à l&#8217;abri de quelqu&#8217;un qui...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>chkrootkit est une application permettant de vérifier la présence de rootkit sur votre linux. Un rootkit est un programme permettant de garder une porte ouverte sur votre système. Ce qui est généralement utilisé par les pirates.</p>
<p>Garder une porte secrète peut servir à diverses choses. Le pirate peut avoir un besoin d&#8217;un service sur votre machine pour envoyer par exemple des spams, récupérer des logs, contenant des informations sensibles&#8230;</p>
<p>chkrootkit vous permettra de faire un scan régulier de votre machine et détecter d&#8217;éventuels attaques. Pour celà il faut au minimum savoir comment utiliser ses fonctions.</p>
<p>chkrootkit se trouve en général dans les dépôts de votre distribution de linux, par exemple sous debian et ubuntu, il suffira de faire <code>apt-get install chkrootkit</code>.</p>
<p>Autrement il est possible de télécharger et d&#8217;installer rapidement chkrootkit :</p>
<pre>
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
tar xvf chkrootkit.tar.gz
cd chkrootkit*
make sense
</pre>
<p>Il faudra posséder les droits du super utilisateur pour lancer le programme</p>
<pre>
sudo ./chkrootkit
</pre>
<p>D&#8217;autres options sont disponibles et c&#8217;est ici que le programme devient intéressant. Un rootkit peut avoir compromis un des programmes de base utilisé par votre distribution, rendant de ce fait le scan inutile. chkrootkit est, si vous regardé attentivement, un script bash utilisant des binaires de votre distribution.</p>
<p>chkrootkit possède une option permettant de préciser un autre chemin pour utiliser ces binaires :</p>
<pre>
./chkrootkit -p path
</pre>
<p>Le chemin peut par exemple être un disque extérieur que vous aurez monté.</p>
<p>Il est possible également de programmer grâce au cron un rapport quotidien de chkrootkit qui vous sera envoyé par mail.</p>
<pre>
sudo crontab -e
</pre>
<p>En ajoutant la ligne suivante et en modifiant le chemin répertoire de chkrootkit ainsi que le destinataire du mail (il est possible de faire <code>which chkrootkit</code> pour connaître son dossier, si vous l&#8217;avez installé par les dépôts) :</p>
<pre>
0 3 * * * (cd /usr/local/chkrootkit; ./chkrootkit 2>&#038;1 | mail -s "chkrootkit output" me@example.com
</pre>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/' rel='bookmark' title='Permanent Link: Installer Ruby on Rails sur Linux'>Installer Ruby on Rails sur Linux</a> <small>Voici quelques lignes de commandes pour installer Ruby on Rails...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li><li><a href='http://www.pasunclou.com/2008/09/05/des-astuces-pour-securiser-votre-wordpress/' rel='bookmark' title='Permanent Link: Des astuces pour sécuriser votre Wordpress'>Des astuces pour sécuriser votre Wordpress</a> <small> Nous ne sommes jamais à l&#8217;abri de quelqu&#8217;un qui...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/05/09/chkrootkit-verifier-la-presene-de-rootkit-sur-v/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Faire cohabiter plusieurs versions de Python</title>
		<link>http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/</link>
		<comments>http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/#comments</comments>
		<pubDate>Tue, 05 May 2009 15:50:54 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[programmation]]></category>

		<category><![CDATA[tutoriaux]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=965</guid>
		<description><![CDATA[Par défaut sur ma distribution de Linux Ubuntu 8.10 je possède deux versions de Python, 2.4 et 2.5.
Prévoyant de développer du code Python seulement pour apprendre le langage, j&#8217;ai décidé d&#8217;installer la dernière version de Python (v3) en compilant les sources (il est également possible de passer par apt-get install python3).
Dans un répertoire temporaire :
je [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/' rel='bookmark' title='Permanent Link: Installer Ruby on Rails sur Linux'>Installer Ruby on Rails sur Linux</a> <small>Voici quelques lignes de commandes pour installer Ruby on Rails...</small></li><li><a href='http://www.pasunclou.com/2009/02/25/installer-cherrypy/' rel='bookmark' title='Permanent Link: Installer CherryPy'>Installer CherryPy</a> <small>CherryPy pour ceux qui seraient tombés au hasard sur cette...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Par défaut sur ma distribution de Linux Ubuntu 8.10 je possède deux versions de Python, 2.4 et 2.5.</p>
<p>Prévoyant de développer du code Python seulement pour apprendre le langage, j&#8217;ai décidé d&#8217;installer la dernière version de Python (v3) en compilant les sources (il est également possible de passer par <code>apt-get install python3</code>).</p>
<p>Dans un répertoire temporaire :<br />
je récupère le dernier tarball de <a href="http://www.python.org/download/">Python</a></p>
<pre>
wget http://www.python.org/download/Python-3.x.x.tgz
</pre>
<p>Je le détarre en utilisant :</p>
<pre>
tar xvf Python-3.x.x.tgz
</pre>
<p>Comme pour (presque) toute archive sous linux un fichier README est présent<br />
La marche à suivre est la suivante<br />
cd Python-3.x.x<br />
./configure<br />
make<br />
make test</p>
<p>Et maintenant vous avez deux choix, si 3.x.x n&#8217;est pas votre version principale faites <code>make altinstall</code> sinon le traditionnel <code>make install</code></p>
<p>Enfin répéter autant de fois ces étapes, pour toutes les versions que vous souhaitez installer.</p>
<p>Pour lancer python v3 :</p>
<pre>
$ python3.0
Python 3.0.1 (r301:69556, May  5 2009, 16:24:20)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/10/installer-ruby-on-rails-sur-linux/' rel='bookmark' title='Permanent Link: Installer Ruby on Rails sur Linux'>Installer Ruby on Rails sur Linux</a> <small>Voici quelques lignes de commandes pour installer Ruby on Rails...</small></li><li><a href='http://www.pasunclou.com/2009/02/25/installer-cherrypy/' rel='bookmark' title='Permanent Link: Installer CherryPy'>Installer CherryPy</a> <small>CherryPy pour ceux qui seraient tombés au hasard sur cette...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installer GeoIP pour PHP sous Ubuntu</title>
		<link>http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/</link>
		<comments>http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/#comments</comments>
		<pubDate>Tue, 05 May 2009 10:08:17 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[programmation]]></category>

		<category><![CDATA[tutoriaux]]></category>

		<category><![CDATA[geoip]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=957</guid>
		<description><![CDATA[GeoIP est un service de MaxMind destiné à récupérer des informations (pays, ville,&#8230;) à partir d&#8217;une IP. Il existe 3 manières de bénéficier de ce service (en pure PHP, grâce à une extension pour PHP et une pour Apache).
Celle qui nous intéresse ici est l&#8217;extension pour PHP. Il est conseillé sur le site de passer [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2008/08/11/installer-curl-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer curl sous ubuntu'>Installer curl sous ubuntu</a> <small>Juste une petite note&#8230; qui peut servir à d&#8217;autres peut-être&#8230;...</small></li><li><a href='http://www.pasunclou.com/2008/11/10/tester-intrepid-ibex-ubuntu-810-sous-windows/' rel='bookmark' title='Permanent Link: Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows'>Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows</a> <small> Si vous voyez de plus en plus de systèmes...</small></li><li><a href='http://www.pasunclou.com/2008/11/18/tester-intrepid-ibex-ubuntu-810-sous-windows-avec-wubi/' rel='bookmark' title='Permanent Link: Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows avec Wubi'>Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows avec Wubi</a> <small> Pour aller plus loin dans la cohabitation de Windows...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>GeoIP est un service de MaxMind destiné à récupérer des informations (pays, ville,&#8230;) à partir d&#8217;une IP. Il existe 3 manières de bénéficier de ce service (en pure PHP, grâce à une extension pour PHP et une pour Apache).</p>
<p>Celle qui nous intéresse ici est l&#8217;extension pour PHP. Il est conseillé sur le site de passer par PECL, malheureusement sous Ubuntu nous avons une erreur de ce type :</p>
<pre>
checking for geoip files in default path... not found
configure: error: Please reinstall the geoip distribution
ERROR: `/tmp/pear/temp/geoip/configure' failed
</pre>
<p>Le plus simple est alors de passer par les dépôts. Si vous êtes sous Mac ou sous une autre distribution de Linux cherchez GeoIP et le nom de votre distribution, en général ce sujet à été largement couvert. Enfin pour les plus courageux, vous pouvez <a href="http://www.maxmind.com/app/php">compiler le package</a>.</p>
<pre>
apt-get install php5-geoip
</pre>
<p>Par défaut, une base de données est installée sur votre machine dans le répertoire <code>/usr/share/GeoIP</code>. Pour bénéficier de la localisation par ville (en version lite) et des informations sur l&#8217;ASP.</p>
<p>Il vous faut récupérer ces deux archives et les décompresser dans le réperoire <code>/usr/share/GeoIP</code> :</p>
<ul>
<li><a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz">GeoLiteCity</a></li>
<li><a href="http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz">GeoIPASPNum</a></li>
</ul>
<p>En ce qui concerne GeoLiteCity.dat renommer ce fichier en GeoIPCity.dat, sinon l&#8217;extension GeoIP ne le prendra pas en compte.</p>
<p>Enfin, étant donné que la liste des pays n&#8217;est pas à jour, vous pouvez télécharger la base contenant les pays et écraser l&#8217;ancienne : http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz</p>
<p>Pour terminer voici un lien vers la doc php : http://uk.php.net/manual/fr/book.geoip.php<br />
Ainsi qu&#8217;un exemple d&#8217;utilisation avec le shell interactif</p>
<pre>
$ php -a
Interactive shell

php > $record = geoip_record_by_name('www.example.com');
php > var_dump($record);
array(10) {
  ["country_code"]=>
  string(2) "US"
  ["country_code3"]=>
  string(3) "USA"
  ["country_name"]=>
  string(13) "United States"
  ["region"]=>
  string(2) "CA"
  ["city"]=>
  string(13) "Beverly Hills"
  ["postal_code"]=>
  string(5) "90210"
  ["latitude"]=>
  float(34.0994987488)
  ["longitude"]=>
  float(-118.414299011)
  ["dma_code"]=>
  int(803)
  ["area_code"]=>
  int(310)
}
</pre>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2008/08/11/installer-curl-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer curl sous ubuntu'>Installer curl sous ubuntu</a> <small>Juste une petite note&#8230; qui peut servir à d&#8217;autres peut-être&#8230;...</small></li><li><a href='http://www.pasunclou.com/2008/11/10/tester-intrepid-ibex-ubuntu-810-sous-windows/' rel='bookmark' title='Permanent Link: Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows'>Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows</a> <small> Si vous voyez de plus en plus de systèmes...</small></li><li><a href='http://www.pasunclou.com/2008/11/18/tester-intrepid-ibex-ubuntu-810-sous-windows-avec-wubi/' rel='bookmark' title='Permanent Link: Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows avec Wubi'>Tester Intrepid Ibex - Ubuntu 8.10 - sous Windows avec Wubi</a> <small> Pour aller plus loin dans la cohabitation de Windows...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Une classe PHP pour récupérer la météo</title>
		<link>http://www.pasunclou.com/2009/04/26/une-classe-php-pour-recuperer-la-meteo/</link>
		<comments>http://www.pasunclou.com/2009/04/26/une-classe-php-pour-recuperer-la-meteo/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 12:45:14 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[programmation]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=948</guid>
		<description><![CDATA[Voici une classe compatible PHP 5 pour récupérer la météo. Pour l&#8217;instancier il faut passer en paramètre le code de votre ville (à récupérer sur le site de Yahoo!Weather - exemple pour Oxford : UKXX0106) ainsi que l&#8217;unité pour la température (c ou f - optionnel c pour Celcius par défaut).
Exemple d&#8217;utilisation avec le shell [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/04/21/plugin-meteo-pour-wordpress/' rel='bookmark' title='Permanent Link: Plugin météo pour Wordpress'>Plugin météo pour Wordpress</a> <small>Voici un plugin (Y!Weather) qui vous donne la météo pour...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Voici une classe compatible PHP 5 pour récupérer la météo. Pour l&#8217;instancier il faut passer en paramètre le code de votre ville (à récupérer sur le site de <a href="http://weather.yahoo.com/">Yahoo!Weather</a> - exemple pour Oxford : UKXX0106) ainsi que l&#8217;unité pour la température (c ou f - optionnel c pour Celcius par défaut).</p>
<p>Exemple d&#8217;utilisation avec le shell interactif :</p>
<p><code></p>
<pre>
$ php -a
Interactive shell

php > include 'class.weather.php';
php > $meteo = new YWeather('UKXX0106', 'c');
php > print_r($meteo);
YWeather Object
(
    [_locationCode:protected] => UKXX0106
    [_urlComplete:protected] => http://weather.yahooapis.com/forecastrss?p=UKXX0106&#038;u=c
    [_unit:protected] => c
    [weather] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [version] => 2.0
                )

            [channel] => SimpleXMLElement Object
                (
                    [title] => Yahoo! Weather - Oxford, UK
                    [link] => http://us.rd.yahoo.com/dailynews/rss/weather/Oxford__UK/*http://weather.yahoo.com/forecast/UKXX0106_c.html
                    [description] => Yahoo! Weather for Oxford, UK
...
php > $channel = $meteo->channel();
php > $item = $meteo->item();
php > print_r($item);
stdClass Object
(
    [condition] => stdClass Object
        (
            [text] => SimpleXMLElement Object
                (
                    [0] => Fair
                )

            [code] => SimpleXMLElement Object
                (
                    [0] => 34
...
</pre>
<p></code></p>

<div class="wp_codebox"><table width="100%" ><tr id="p94818"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
</pre></td><td class="code" id="p948code18"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Copyright (c) 2009, Kevin Etienne, http://www.pasunclou.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the &quot;Software&quot;), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @author Kevin Etienne &lt;etienne.kevin@gmail.com&gt;
 * @version 0.1
 * @package YWeather
 */</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * This class get the Weather from Yahoo!Weather and
 * parses it into a weather object with usable attributes.
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> YWeather <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Store the location's code of the city
   * @private
   */</span>
  protected <span style="color: #000088;">$_locationCode</span><span style="color: #339933;">;</span>
  <span style="color: #009933; font-style: italic;">/**
   * Store the url of the API
   * @private;
   */</span>
  protected <span style="color: #000088;">$_urlComplete</span><span style="color: #339933;">;</span>
  <span style="color: #009933; font-style: italic;">/**
   * Store the unit's preference of the user and force him to retrieve the unit
   * throught the API (if the unit is not valid)
   * @private
   */</span>
  protected <span style="color: #000088;">$_unit</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * create an instance of simpleXML
   * 
   * @param string $location code belong to the location (ex: UKXX0106)
   * @param char $unit unit for temperature (c or f) 
   */</span>  
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #339933;">,</span> <span style="color: #000088;">$unit</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'c'</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>_locationCode <span style="color: #339933;">=</span> <span style="color: #000088;">$location</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_unit <span style="color: #339933;">=</span> <span style="color: #000088;">$unit</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_urlComplete <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_buildURI<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_locationCode<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_unit<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;">weather</span> <span style="color: #339933;">=</span> simplexml_load_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_urlComplete<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * call a protected method
   *
   * @param string $methodName name of the method
   * @param string $args N/A
   * @return an object for the Yahoo!Weather's namespace
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$methodName</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;_get&quot;</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/ucfirst"><span style="color: #990000;">ucfirst</span></a><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$methodName</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/method_exists"><span style="color: #990000;">method_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$method</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: #009933; font-style: italic;">/**
   * return the complete URL to retrieve the Yahoo API
   * 
   * @param string $location code belongs to the location
   * @param char $unit unit in (c)elcius or (f)ahraneit
   * @return url composed with $location and $unit
   */</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> _buildURI<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #339933;">,</span> <span style="color: #000088;">$unit</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'c'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$urlComplete</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://weather.yahooapis.com/forecastrss?'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$urlComplete</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'p='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$location</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$urlComplete</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$unit</span> ? <span style="color: #0000ff;">'&amp;u='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$unit</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$urlComplete</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Largely inspired by the snippet originately written by
   * {@link http://pkarl.com Pete Karl} (2009).
   *
   * return an object with the location, units, wind, atmosphere and
   * astronomy parameters
   * 
   * @return object from the API namespace
   */</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> _getChannel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$yWeather</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">weather</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://xml.weather.yahoo.com/ns/rss/1.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$yWeather</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$channel_item</span><span style="color: #009900;">&#41;</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$channel_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$yw_channel</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$yw_channel</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Largely inspired by the snippet originately written by
   * {@link http://pkarl.com Pete Karl} (2009).
   * 
   * return an object with the geolocalisation, condition and forecast
   * 
   * return object from the API namespace
   */</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> _getItem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$yWeather</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">weather</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">channel</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://xml.weather.yahoo.com/ns/rss/1.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$yWeather</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$yw_item</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$yw_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attr</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;">$k</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'day'</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$day</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'forecast'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$yw_forecast</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$day</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #000088;">$yw_forecast</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$x</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$k</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$yw_forecast</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * return the URL
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_urlComplete<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Télécharger la classe <a href='http://www.pasunclou.com/wp-content/uploads/2009/04/classweather.php'>YWeather.php</a></p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/04/21/plugin-meteo-pour-wordpress/' rel='bookmark' title='Permanent Link: Plugin météo pour Wordpress'>Plugin météo pour Wordpress</a> <small>Voici un plugin (Y!Weather) qui vous donne la météo pour...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/04/26/une-classe-php-pour-recuperer-la-meteo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Plugin météo pour Wordpress</title>
		<link>http://www.pasunclou.com/2009/04/21/plugin-meteo-pour-wordpress/</link>
		<comments>http://www.pasunclou.com/2009/04/21/plugin-meteo-pour-wordpress/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 16:18:48 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[cms]]></category>

		<category><![CDATA[programmation]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=933</guid>
		<description><![CDATA[Voici un plugin (Y!Weather) qui vous donne la météo pour Wordpress. Ce plugin météo est un widget qui s&#8217;installe et se configure facilement.
Ce plugin se base sur le service de Yahoo! pour avoir la météo. Pour l&#8217;utiliser vous devez connaître le code de votre ville en allant sur le site de Yahoo!Weather.
Exemple pour Oxford, je [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/04/26/une-classe-php-pour-recuperer-la-meteo/' rel='bookmark' title='Permanent Link: Une classe PHP pour récupérer la météo'>Une classe PHP pour récupérer la météo</a> <small>Voici une classe compatible PHP 5 pour récupérer la météo....</small></li><li><a href='http://www.pasunclou.com/2008/08/29/plugin-wordpress-fuzz/' rel='bookmark' title='Permanent Link: Plugin Wordpress pour fuzz'>Plugin Wordpress pour fuzz</a> <small>Ce plugin pour Wordpress permet d&#8217;affichez les news du célèbre...</small></li><li><a href='http://www.pasunclou.com/2008/09/29/ecrire-un-plugin-wordpress/' rel='bookmark' title='Permanent Link: Ecrire un plugin pour WordPress'>Ecrire un plugin pour WordPress</a> <small> Il arrive quelques fois de ne pas trouver son...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Voici un plugin (<a href="http://www.pasunclou.com/wp-content/uploads/2009/04/yweather.zip">Y!Weather</a>) qui vous donne la météo pour Wordpress. Ce plugin météo est un widget qui s&#8217;installe et se configure facilement.<br />
Ce plugin se base sur le service de Yahoo! pour avoir la météo. Pour l&#8217;utiliser vous devez connaître le code de votre ville en allant sur le site de <a href="http://weather.yahoo.com/">Yahoo!Weather</a>.</p>
<p>Exemple pour Oxford, je tape dans la barre de recherche Oxford</p>
<div id="attachment_934" class="wp-caption aligncenter" style="width: 436px"><img class="size-full wp-image-934" title="yahoo1" src="http://www.pasunclou.com/wp-content/uploads/2009/04/yahoo1.png" alt="Trouver son code météo sous Yahoo!" width="426" height="180" /><p class="wp-caption-text">Trouver son code météo sous Yahoo!</p></div>
<p>Et je récupére le code dans la barre d&#8217;adresse : UKXX0106</p>
<div id="attachment_935" class="wp-caption aligncenter" style="width: 432px"><img class="size-full wp-image-935" title="yahoo2" src="http://www.pasunclou.com/wp-content/uploads/2009/04/yahoo2.png" alt="Récupérer son code météo sous Yahoo!" width="422" height="33" /><p class="wp-caption-text">Récupérer son code météo sous Yahoo!</p></div>
<p>Pour installer le plugin il faut</p>
<ul>
<li>dézipper le plugin dans votre répertoire wp-content/plugins</li>
<li>se rendre dans l&#8217;administration et activer le plugin</li>
<li>dans le menu widget configurer le widget</li>
<li>et entrer votre code et l&#8217;unité pour la température (f pour fahrenheit et c pour degrés)</li>
</ul>
<p>Ce plugin est tout nouveau, la prochaine fonctionnalité sera la description du temps qu&#8217;il fait en anglais ou en français.<br />
Ce plugin a été seulement testé sous Wordpress 2.7, s&#8217;il fonctionne sur des versions antérieurs merci de laisser un commentaire.<br />
Ce plugin n&#8217;est pas compatible avec PHP &lt; 5.</p>
<p>Si vous avez des commentaires ou des suggestions, n&#8217;hésitez pas à les exposer.</p>
<p>Télécharger <a href="http://www.pasunclou.com/wp-content/uploads/2009/04/yweather.zip">Y!Weather</a> (Merci Louiselle)</p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/04/26/une-classe-php-pour-recuperer-la-meteo/' rel='bookmark' title='Permanent Link: Une classe PHP pour récupérer la météo'>Une classe PHP pour récupérer la météo</a> <small>Voici une classe compatible PHP 5 pour récupérer la météo....</small></li><li><a href='http://www.pasunclou.com/2008/08/29/plugin-wordpress-fuzz/' rel='bookmark' title='Permanent Link: Plugin Wordpress pour fuzz'>Plugin Wordpress pour fuzz</a> <small>Ce plugin pour Wordpress permet d&#8217;affichez les news du célèbre...</small></li><li><a href='http://www.pasunclou.com/2008/09/29/ecrire-un-plugin-wordpress/' rel='bookmark' title='Permanent Link: Ecrire un plugin pour WordPress'>Ecrire un plugin pour WordPress</a> <small> Il arrive quelques fois de ne pas trouver son...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/04/21/plugin-meteo-pour-wordpress/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Erreur  PHPUnit</title>
		<link>http://www.pasunclou.com/2009/04/17/erreur-phpunit/</link>
		<comments>http://www.pasunclou.com/2009/04/17/erreur-phpunit/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 16:33:19 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[programmation]]></category>

		<category><![CDATA[linux]]></category>

		<category><![CDATA[phpunit]]></category>

		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=929</guid>
		<description><![CDATA[Je viens d&#8217;être confronté à une petite erreur avec PHPUnit dont voici l&#8217;extrait :
Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 44
Fatal error: require_once(): Failed opening required 'PHPUnit/Util/Filter.php' (include_path='.:/usr/local/lib/php:/home/chatlow/svn/zf/trunk/library') in /usr/bin/phpunit on line 44
Après quelques recherches sur le Web et dans mon dossier usr


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/' rel='bookmark' title='Permanent Link: Faire cohabiter plusieurs versions de Python'>Faire cohabiter plusieurs versions de Python</a> <small>Par défaut sur ma distribution de Linux Ubuntu 8.10 je...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Je viens d&#8217;être confronté à une petite erreur avec PHPUnit dont voici l&#8217;extrait :</p>
<pre>Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 44
Fatal error: require_once(): Failed opening required 'PHPUnit/Util/Filter.php' (include_path='.:/usr/local/lib/php:/home/chatlow/svn/zf/trunk/library') in /usr/bin/phpunit on line 44</pre>
<p>Après quelques recherches sur le Web et dans mon dossier <code>usr</code, il s'avère qu'il faut mettre dans l'include path de php le répertoire suivant pour ubuntu :</p>
<pre>/usr/share/php</pre>
<p>Pour d&#8217;autres distributions le répertoire peut être le suivant :</p>
<pre>/usr/local/lib/php</pre>
<p>Et voilà, à nous les joies des tests</p>
<p>PS : par défaut ce répertoire était dans mon php.ini, je l&#8217;ai supprimé, vu qu&#8217;il était commenté&#8230;</p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/05/installer-geoip-pour-php-sous-ubuntu/' rel='bookmark' title='Permanent Link: Installer GeoIP pour PHP sous Ubuntu'>Installer GeoIP pour PHP sous Ubuntu</a> <small>GeoIP est un service de MaxMind destiné à récupérer des...</small></li><li><a href='http://www.pasunclou.com/2009/05/05/faire-cohabiter-plusieurs-versions-de-python/' rel='bookmark' title='Permanent Link: Faire cohabiter plusieurs versions de Python'>Faire cohabiter plusieurs versions de Python</a> <small>Par défaut sur ma distribution de Linux Ubuntu 8.10 je...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/04/17/erreur-phpunit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Modèle et contrôleur avec CodeIgniter (partie 3)</title>
		<link>http://www.pasunclou.com/2009/04/16/modele-controlleur-codeigniter-partie-3/</link>
		<comments>http://www.pasunclou.com/2009/04/16/modele-controlleur-codeigniter-partie-3/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 19:16:24 +0000</pubDate>
		<dc:creator>ekevin</dc:creator>
		
		<category><![CDATA[framework]]></category>

		<category><![CDATA[programmation]]></category>

		<category><![CDATA[codeigniter]]></category>

		<guid isPermaLink="false">http://www.pasunclou.com/?p=872</guid>
		<description><![CDATA[Dans la partie précédente nous avons vu comment se servir de la base de données avec CodeIgniter, cependant nous n&#8217;avons pas réellement respecté la logique de séparation du MVC. C&#8217;est ce que nous allons faire dans ce tutoriel (enfin presque). Nous avons vu également comment déclarer une nouvelle action dans un contrôleur. Dans cette partie, [...]


Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/27/vue-avec-codeigniter-partie-4/' rel='bookmark' title='Permanent Link: Vue avec CodeIgniter (partie 4)'>Vue avec CodeIgniter (partie 4)</a> <small>Les vues permettent de séparer le fonctionnement de l&#8217;application avec...</small></li><li><a href='http://www.pasunclou.com/2009/03/25/configurer-et-utiliser-la-base-de-donnees-avec-codeigniter-partie-2/' rel='bookmark' title='Permanent Link: Configurer et utiliser la base de données avec CodeIgniter (partie 2)'>Configurer et utiliser la base de données avec CodeIgniter (partie 2)</a> <small>Pour ce deuxième tutoriel, vous devez avoir installé CodeIgniter sur...</small></li><li><a href='http://www.pasunclou.com/2009/03/11/introduction-et-installation-de-codeigniter-partie-1/' rel='bookmark' title='Permanent Link: Introduction et installation de CodeIgniter (partie 1)'>Introduction et installation de CodeIgniter (partie 1)</a> <small>Introduction CodeIgniter est un framework PHP destiné à réduire votre...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Dans la partie précédente nous avons vu comment se servir de la base de données avec CodeIgniter, cependant nous n&#8217;avons pas réellement respecté la logique de séparation du MVC. C&#8217;est ce que nous allons faire dans ce tutoriel (enfin presque). Nous avons vu également comment déclarer une nouvelle action dans un contrôleur. Dans cette partie, nous allons créer notre premier modèle avec ses méthodes ainsi qu&#8217;un contrôleur. Nous ne verrons pas comment envoyer des données à la vue. Ceci, sera le sujet du prochain tutoriel.</p>
<h2>Implementation d&#8217;un premier modèle</h2>
<p>Un modèle dans une architecture MVC se charge de communiquer avec les données qui peuvent être dans une base de données, dans un fichier, sur un site extérieur, dans un flux RSS&#8230;<br />
Notre premier modèle va se charger de correspondre avec notre base de données sous MySQL. Pour ceux venant du deuxième tutoriel nous n&#8217;altérerons que la table pour ajouter une ville et un pays.</p>
<p>Pour altérer une table sous PhpMyAdmin vous devez cliquer sur la base de données (<code>tut_pasunclou</code>) puis sur la table (<code>Users</code>) et vous devriez voir ceci :</p>
<div id="attachment_874" class="wp-caption aligncenter" style="width: 511px"><img class="size-full wp-image-874" title="alter_phpmyadmin" src="http://www.pasunclou.com/wp-content/uploads/2009/03/alter_phpmyadmin.png" alt="Menu pour altérer une table sous PhpMyadmin" width="501" height="57" /><p class="wp-caption-text">Menu pour altérer une table sous PhpMyadmin</p></div>
<p>Nous ajoutons donc 3 champs (<code>city, country, colour</code>) et des données dont vous trouverez les détails ci-dessous (n&#8217;oubliez pas d&#8217;effacer vos anciennes données ou de les adapter en conséquences).</p>
<p>Détail de la table :</p>
<pre>CREATE TABLE Users (
  idUsers INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  username VARCHAR(45) NOT NULL,
  city VARCHAR(45) NOT NULL,
  country VARCHAR(45) NOT NULL,
  colours VARCHAR(45) NOT NULL,
  PRIMARY KEY(idUsers)
);

INSERT INTO Users (username, city, country, colours) VALUES ("Kevin", "Oxford", "Royaume-Uni", "vert");
INSERT INTO Users (username, city, country, colours) VALUES ("Raoul", "Paris", "France", "bleu");
INSERT INTO Users (username, city, country, colours) VALUES ("Esmeralda", "Santa Fe", "Argentine", "rouge");
INSERT INTO Users (username, city, country, colours) VALUES ("Nathalie", "Barcelone", "Espagne", "bleu");
INSERT INTO Users (username, city, country, colours) VALUES ("Naomie", "Lille", "France", "rouge");
</pre>
<p>Dans notre modèle, nous voulons pouvoir consulter, ajouter et mettre à jour des données. Nous allons implenter les méthodes suivantes :</p>
<ul>
<li>getAll() : qui nous permettra de récupérer toutes les entrées</li>
<li>getByColour($colour) : nous pourrons sélectionner les données en filtrant par couleur</li>
<li>updateName($name) : mettra à jour la couleur d&#8217;un profil en indiquant le pseudo</li>
</li>
<p>Nous appellerons notre fichier <code>users_model.php</code> et nous le placerons dans le dossier <code>application > models</code>.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87227"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p872code27"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Users_model <span style="color: #000000; font-weight: bold;">extends</span> Model <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> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">Model</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</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: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> getAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">free_result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Cette classe est assez simple, en premier nous définissons un constructeur qui va hériter de la classe <code>Model</code> se situant dans le répertoire system > libraries.<br />
En second nous définissons une méthode qui se chargera de récupérer tous les articles de notre base de données grâce à la fonction <code>$this->db->get('Users')</code> ou articles est le nom de notre table (plus d&#8217;informations dans le fichier <code>system > database > DB_active_rec.php</code> et dans la documentation).</p>
<p>Nous stockons alors le résultat dans une variable ($data) avant de libérer la mémoire associée à cette requête. Il n&#8217;est pas nécessaire de procéder à cette étape si vous vous contentez de quelques requêtes car PHP s&#8217;occupe de libérer cette mémoire pour vous. Cependant il est bon de démarrer avec de bonnes pratiques.</p>
<p>Actuellement notre site ne fait pas grand chose si ce n&#8217;est récupérer une table dans une base de données. Passons maintenant au contrôleur de ce modèle qui se chargera de faire le médiateur entre le modèle est la vue.</p>
<h2>Le controlleur</h2>
<p>Le controlleur va se charger de récupérer les données du modèle et de les envoyer à la vue. Comme pour le modèle nous définissons une classe qui va étendre (extends) le controlleur de CI (<code>application > controllers > users.php</code>).</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87228"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p872code28"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Articles <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enable_profiler</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> index<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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Articles_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Si vous avez lu le paragraphe ci-dessus à propos du contrôleur, vous remarquerez des similarités avec le modèle de tout à l&#8217;heure.</p>
<p>Premièrement nous héritons du contrôleur de CI qui lui-même héritant de <code>CI_Base</code> (<code>Base4.php</code> ou <code>Base5.php</code> en fonction de votre version de PHP). Entre autre cet héritage permet d&#8217;avoir accès à toutes les classes instanciées dans le front contrôleur (<code>system > codeigniter > CodeIgniter.php</code>) comme config, input, benchmark&#8230; et permet si vous l&#8217;avez déclaré d&#8217;écrire dans un log que le Contrôleur a été initialisé.</p>
<p>Deuxièmement, nous remarquons le nom de notre classe (le modèle <code>users_model</code>) dans la méthode <code>index()</code> ainsi que la méthode <code>getAll()</code>. La méthode <code>index()</code> va charger la classe <code>Users_model</code>, par l&#8217;intermédiaire de la ligne suivante :</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87229"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p872code29"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Cet appel est une autre manière de créer une instance du modèle. Nous aurions pu l&#8217;instancier manuellement mais CodeIgniter fournit des méthodes pour appeler nos différentes classes. De la même façon nous pouvons charger une librairie, un plugin ou encore un helper en remplaçant model respectivement par library, plugin et helper (<a href="http://codeigniter.com/user_guide/libraries/loader.html">documentation sur le Loader</a>).</p>
<p>La méthode <code>model</code> se charge de vérifier si votre classe existe (ou vos classes, vous pouvez définir un tableau). </p>
<p>Enfin nous récupérons par l&#8217;intermédiaire du modèle tous les résultats contenus dans notre table Users. Ce résultat est stocké dans <code>$data</code>.</p>
<p>Nous ne mettrons pas en forme le résultat de cette requête, nous nous contenterons d&#8217;ajouter un <code>var_dump($data)</code> à la fin de notre méthode <code>index()</code>.</p>
<p>À ce niveau voici ce que donne notre programme en pointant le navigateur sur http://localhost/users.</p>
<div id="attachment_901" class="wp-caption aligncenter" style="width: 413px"><img src="http://www.pasunclou.com/wp-content/uploads/2009/04/03-01.png" alt="Apercu du var_dump et du profiler de CodeIgniter" title="Notre premier modèle et controlleur" width="403" height="489" class="size-full wp-image-901" /><p class="wp-caption-text">Apercu du var_dump et du profiler de CodeIgniter</p></div>
<p>La méthode index est la première méthode qu&#8217;il faut définir dans un contrôleur. C&#8217;est la méthode par défaut. Ainsi quand nous demandons à notre navigateur d&#8217;afficher http://localhost/users nous appelons le contrôleur articles et la méthode index. En affichant http://localhost/users/index nous devrions avoir le même résultat.</p>
<p>Avant de coder nos deux dernières méthodes, arrêtons-nous quelques instants sur cette ligne</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87230"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p872code30"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enable_profiler</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Vous avez sans doute remarqué que nous avons quelques informations en dessous de nos données affichées avec var_dump. C&#8217;est le résultat du profiler, il nous donne des informations basiques sur :</p>
<ul>
<li>le fichier utilisé</li>
<li>le temps d&#8217;affichage</li>
<li>la consommation mémoire</li>
<li>GET et POST</li>
<li>et enfin la requête effectué sur la BDD</li>
</ul>
<p>Ces informations sont très utiles si le résultat affiché n&#8217;est pas celui escompté.</p>
<p>Ci-dessous, voici le code à ajouter à notre modèle et à notre contrôleur pour permettre de consulter les données de notre table par couleur ainsi que de mettre à jour la couleur d&#8217;un utilisateur.</p>
<p>Users_model.php</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87231"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p872code31"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getByColour<span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users'</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;">'colours'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">free_result</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updateName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</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;">'colours'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$colour</span><span style="color: #339933;">,</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;">db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</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;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>users.php</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87232"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p872code32"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> couleur<span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// la couleur est-elle définie ? si non renvoie à index</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/users/index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getByColour</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// la couleur et le nom sont-ils définies ?</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$colour</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users/index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Rien de bien compliqué jusque maintenant, il suffit de comprendre comment travailler avec Active Record dans CodeIgniter. Cependant, nous remarquerons que nous ne respectons plus un principe fondamental de la Programmation Orientée Objet. Le DRY (Don&#8217;t Repeat Yourself - Ne pas se répéter). Il nous faut donc re-factoriser.</p>
<p>Il existe des multitudes de solutions pour se faire. Nous pourrions par exemple mettre le chargement du modèle <code>Users_model</code> dans le constructeur de la classe et y ajouter notre helper.</p>
<p>Nous pourrions également créer de nouveaux helpers ou une librairie mais leurs usages ne conviennent pas vraiment dans notre cas.</p>
<p>Nous pouvons aussi pour éviter d&#8217;avoir un fichier trop long, créer une nouvelle classe qui sera étendue par tous nos contrôleurs. Pour ma part, je préfère cette solution.</p>
<p>Cette classe doit se situer dans le dossier <code>application > libraries</code> et doit se nommer <code>MY_Controller.php</code> (<a href="http://codeigniter.com/user_guide/general/core_classes.html">voir la doc</a>)</p>
<p>MY_Controller.php</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87233"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p872code33"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MY_Controller <span style="color: #000000; font-weight: bold;">extends</span> Controller <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> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span><span style="color: #004000;">Controller</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enable_profiler</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</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;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">model</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Users_model'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                          
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Voici la nouvelle version de notre contrôleur<br />
users.php</p>

<div class="wp_codebox"><table width="100%" ><tr id="p87234"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p872code34"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Users <span style="color: #000000; font-weight: bold;">extends</span> MY_Controller <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> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<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: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> couleur<span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// la couleur est-elle définie ? si non renvoie à index</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/users/index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$colour</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getByColour</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// la couleur et le nom sont-ils définies ?</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$colour</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'users/index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Users_model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$colour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://www.php.net/var_dump"><span style="color: #990000;">var_dump</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Nous pouvons enfin accéder à nos deux nouvelles fonctions en tapant http://localhost/users/couleur/bleu et http://localhost/users/update/kevin/violet</p>
<p>Il ne nous reste plus qu&#8217;à envoyer nos données à notre vue pour avoir un résultat. Nous nous occuperons des templates dans la prochaine partie.</p>


<p>Related posts:<ol><li><a href='http://www.pasunclou.com/2009/05/27/vue-avec-codeigniter-partie-4/' rel='bookmark' title='Permanent Link: Vue avec CodeIgniter (partie 4)'>Vue avec CodeIgniter (partie 4)</a> <small>Les vues permettent de séparer le fonctionnement de l&#8217;application avec...</small></li><li><a href='http://www.pasunclou.com/2009/03/25/configurer-et-utiliser-la-base-de-donnees-avec-codeigniter-partie-2/' rel='bookmark' title='Permanent Link: Configurer et utiliser la base de données avec CodeIgniter (partie 2)'>Configurer et utiliser la base de données avec CodeIgniter (partie 2)</a> <small>Pour ce deuxième tutoriel, vous devez avoir installé CodeIgniter sur...</small></li><li><a href='http://www.pasunclou.com/2009/03/11/introduction-et-installation-de-codeigniter-partie-1/' rel='bookmark' title='Permanent Link: Introduction et installation de CodeIgniter (partie 1)'>Introduction et installation de CodeIgniter (partie 1)</a> <small>Introduction CodeIgniter est un framework PHP destiné à réduire votre...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pasunclou.com/2009/04/16/modele-controlleur-codeigniter-partie-3/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 8.652 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2009-07-04 07:01:06 -->
