<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Mon, 09 Mar 2026 03:42:15 +0100 -->
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Wiki]]></title>
		<atom:link href="https://www.phpboost.com/syndication/rss/wiki/7" rel="self" type="application/rss+xml"/>
		<link>https://www.phpboost.com</link>
		<description><![CDATA[Derniers articles de la catégorie Créer un module]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>fr</language>
		<generator>PHPBoost</generator>
		
            <item>
                <title><![CDATA[1. Les bases : structure du module]]></title>
                <link>https://www.phpboost.com/wiki/1-les-bases-structure-du-module</link>
                <guid>https://www.phpboost.com/wiki/1-les-bases-structure-du-module</guid>
                <description><![CDATA[Nous allons voir les bases de la création d'un module à travers cet article.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-creation-du-dossier-du-module">Création du dossier du module</h2><br />

<br />
<br />
<br />
<br />
<br />
Dans un premier temps, il va falloir <strong>créer un dossier à la racine de PHPBoost</strong> contenant tous les fichiers du module.<br />
<br />
<strong>Le choix du nom du dossier est important</strong> puisqu'il sera l'identifiant du module mais sera également présent dans les différentes urls.<br />
<br />
Il est préférable de choisir un nom anglais pour rester cohérent avec le reste de PHPBoost.<br />
<br />
Par exemple pour un module dictionnaire, il conviendrait parfaitement de choisir dictionary.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-mise-en-place-des-sous-dossiers">Mise en place des sous-dossiers</h2><br />

<br />
<br />
<br />
<br />
<br />
Plusieurs dossiers sont à créer dans le dossier de votre module :<br />
<br />
<ul class="formatter-ul">
<li class="formatter-li"> <strong>controllers</strong> : contiendra tous les contrôleurs permettant d'afficher vos différentes pages.
</li><li class="formatter-li"> <strong>lang</strong> : contiendra les dossiers de langue de votre module.
</li><li class="formatter-li"> <strong>phpboost</strong> : contiendra le gestionnaire d'extensions et les différentes extensions qui permettent l'interaction entre modules.
</li><li class="formatter-li"> <strong>services</strong> : contiendra les services liés à vos objets, les différentes actions vers la base de données et la définition des autorisations du module.
</li><li class="formatter-li"> <strong>templates</strong> : contiendra tous les templates de vos différentes pages.
</li><li class="formatter-li"> <strong>util</strong> : contiendra les fonctions utiles du module, comme le générateur d'urls et la définition des liens du menu du module dans l'administration.<br />
<br />
</li></ul><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-creation-du-fichier-de-configuration-config-ini">Création du fichier de configuration : config.ini</h2><br />

<br />
<br />
<br />
<br />
<br />
Le fichier <strong>config.ini</strong> contient toutes les informations relatives au module, à l'exception de son nom et de sa description, qui seront placés dans les dossiers de langue.<br />
<br />
Il faut créer ce fichier <strong>à la racine du module</strong>.<br />
<br />
Celui-ci doit contenir au minimum les informations suivantes :<br />
<div class="formatter-container formatter-code code-EXEMPLE"><span class="formatter-title">Code EXEMPLE : </span><div class="formatter-content"><pre style="display:inline;"><pre class="exemple" style="font-family:monospace;">addon_type             = "module"
author                 = "Nickname"
author_mail            = "nickname@email.com"
author_website         = "https://www.phpboost.com"
date                   = "2013/13/07"
version                = "5.2.0"
compatibility          = "5.2"
admin_menu             = "modules"
home_page              = "index.php"
admin_main_page        = "index.php?url=/admin"</pre></pre></div></div><br />
<div class="formatter-container formatter-code code-EXPLICATION"><span class="formatter-title">Code EXPLICATION : </span><div class="formatter-content"><pre style="display:inline;"><pre class="explication" style="font-family:monospace;">addon_type             = "module"
author                 = "Auteur du module"
author_mail            = "Adresse email de l'auteur"
author_website         = "Lien vers la page de l'auteur"
date                   = "Date de création sous forme : AAAA/MM/JJ"
version                = "Version du module"
compatibility          = "Version de PHPBoost compatible avec le module"
admin_menu             = "Choix de l'endroit où le menu doit apparaître dans l'administration. Vous avez le choix entre : administration|tools|members|content|modules"
home_page              = "Chemin vers la page principale du module"
admin_main_page        = "Chemin vers la page de configuration du module"</pre></pre></div></div><br />
<br />
D'autres choix sont disponibles :<br />
<div class="formatter-container formatter-code code-EXEMPLE"><span class="formatter-title">Code EXEMPLE : </span><div class="formatter-content"><pre style="display:inline;"><pre class="exemple" style="font-family:monospace;">contribution_interface = "index.php?url=/add"
php_version            = "5.6"
enabled_features       = "comments, notation, newcontent"
repository             = "https://dl.phpboost.com/unofficial_modules.xml"
rewrite_rules[]        = "RewriteRule ^...."</pre></pre></div></div><br />
<div class="formatter-container formatter-code code-EXPLICATION"><span class="formatter-title">Code EXPLICATION : </span><div class="formatter-content"><pre style="display:inline;"><pre class="explication" style="font-family:monospace;">contribution_interface = "Chemin vers la page de contribution du module"
php_version            = "Version minimum de PHP nécessaire pour executer le module"
enabled_features       = "Liste des addons disponibles sur le module. Choix multiple : comments, notation, newcontent. "
repository             = "adresse du fichier xml du repository pour les mises à jour"
rewrite_rules[]        = "Règles de réécriture"</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-copyright">Copyright</h2><br />

<br />
<br />
<br />
<br />
<br />
Insérez un copyright dans toutes les pages php de votre module. Celui-ci doit être de la forme suivante (remplacez les différentes valeurs par ce qui convient dans l'entête) :<br />
<br />
<div class="formatter-container formatter-code code-EXEMPLE"><span class="formatter-title">Code EXEMPLE : </span><div class="formatter-content"><pre style="display:inline;"><pre class="exemple" style="font-family:monospace;">/**
 * This the config file of the module
 * @copyright   © 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Firstname LASTNAME <nickname@email.com>
 * @version     PHPBoost 5.2 - last update: 2019 01 01
 * @since       PHPBoost 3.0 - 2012 06 25
 * @contributor Firstname LASTNAME <nickname@email.com>
*/</pre></pre></div></div><br />
<div class="formatter-container formatter-code code-EXPLICATIONS"><span class="formatter-title">Code EXPLICATIONS : </span><div class="formatter-content"><pre style="display:inline;"><pre class="explications" style="font-family:monospace;">/**
 * Courte description du fichier (optionnelle et SANS le tag @desc qui n'existe plus)
 * @copyright   dates d'existence de PHPBoost et nom des ayants droit
 * @license     adresse et nom de la licence du fichier
 * @author      nom et email de l'auteur du fichier
 * @version     dernière version de PHPBoost compatible avec le fichier - date de dernière mise à jour du fichier (à modifier à chaque modification du fichier)
 * @since       version de PHPBoost lors de la création du fichier et date de création du fichier 
 * @contributor nom et email de tout contributeur sauf s'il en est l'auteur
*/</pre></pre></div></div><br />
<br />
<span class="message-helper bgc notice">Vous pouvez aussi utiliser une autre licence de la GPLv3 du moment qu'elle soit <a class="offload" href="https://www.gnu.org/licenses/license-list.fr.html#GPLCompatibleLicenses">compatible GPLv3</a></span><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-mise-en-place-des-langues-du-module">Mise en place des langues du module</h2><br />

<br />
<br />
<br />
<br />
<br />
Dans le dossier <strong>lang</strong>, créez un premier sous-dossier : <strong>french</strong>. Nous allons y créer deux fichiers : le fichier contenant la description du module et le fichier de langue utilisé pour le module.<br />
<br />
Les étapes suivantes peuvent être reproduites pour ajouter la langue anglaise (avec la création d'un dossier <strong>english</strong>) ou tout autre langue.<br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-creation-du-fichier-de-description-du-module-desc-ini">Création du fichier de description du module : desc.ini</h3><br />

<br />
<br />
<br />
<br />
<br />
Créez le fichier <em>desc.ini</em> dans le dossier <strong>french</strong>.<br />
<br />
Celui-ci doit contenir (dans la langue concernée, français dans cet exemple) :<br />
<br />
<div class="formatter-container formatter-code code-INI"><span class="formatter-title">Code INI : </span><div class="formatter-content"><pre style="display:inline;"><pre class="ini" style="font-family:monospace;">name="Le nom de votre module"
desc="La description de votre module"</pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-creation-du-fichier-de-langue-du-module-common-php">Création du fichier de langue du module : common.php</h3><br />

<br />
<br />
<br />
<br />
<br />
Nous allons mettre en place le fichier <em>common.php</em> qui sera utilisé dans les chapitres suivant. Commencez par y indiquer le nom de votre module (en remplaçant <em>ModuleName</em> par le nom de votre module) comme suit :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Insérer le copyright ici</span>
 <span style="color: #008000; font-style: italic;">####################################################
</span> <span style="color: #008000; font-style: italic;">#French  #
</span> <span style="color: #008000; font-style: italic;">####################################################
</span><span style="color: #000080;">$lang</span><span style="color: #8000FF;">&#91;</span><span style="color: #808080;">'module_title'</span><span style="color: #8000FF;">&#93;</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'ModuleName'</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-mise-en-place-du-generateur-d-urls">Mise en place du Générateur d'urls</h2><br />

<br />
<br />
<br />
<br />
<br />
Le générateur d'urls est utilisé pour éviter de réécrire à chaque fois chaque url. Il suffira d'appeler une de ses méthodes lorsqu'il est nécessaire de renvoyer vers une url ou d'afficher une url.<br />
<br />
Créez le fichier <em>ModuleNameUrlBuilder.class.php</em> dans le dossier <strong>util</strong> de votre module.<br />
<br />
Nous allons y placer deux méthodes pour le moment : <em>configuration()</em> qui permettra de générer le lien vers l'administration du module et <em>home()</em> qui permettra de générer le lien vers la page d'accueil du module :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Insérer le copyright ici</span>
<span style="color: #0000FF; font-weight: bold;">class</span> ModuleNameUrlBuilder
<span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">private</span> static <span style="color: #000080;">$dispatcher</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">'/ModuleName'</span><span style="color: #8000FF;">;</span>
<span style="color: #008000; font-style: italic;">/**
 * @return Url
 */</span>
<span style="color: #0000FF; font-weight: bold;">public</span> static <span style="color: #0000FF; font-weight: bold;">function</span> configuration<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">return</span> DispatchManager<span style="color: #8000FF;">::</span><span style="color: #000000;">get_url</span><span style="color: #8000FF;">&#40;</span><span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000080;">$dispatcher</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'/admin/config'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #008000; font-style: italic;">/**
 * @return Url
 */</span>
<span style="color: #0000FF; font-weight: bold;">public</span> static <span style="color: #0000FF; font-weight: bold;">function</span> home<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$param</span> <span style="color: #8000FF;">=</span> <span style="color: #808080;">''</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
<span style="color: #0000FF; font-weight: bold;">return</span> DispatchManager<span style="color: #8000FF;">::</span><span style="color: #000000;">get_url</span><span style="color: #8000FF;">&#40;</span><span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000080;">$dispatcher</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'/'</span> <span style="color: #8000FF;">.</span> <span style="color: #000080;">$param</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-mise-en-place-de-la-page-d-index-du-module">Mise en place de la page d'index du module</h2><br />

<br />
<br />
<br />
<br />
<br />
La page <em>index.php</em> permet de diriger l'affichage vers tel ou tel contrôleur en fonction de l'url appelée. Nous allons ici créer un premier lien vers le contrôleur d'administration du module si l'url de configuration est appelée. Pour mettre en place d'autres liens, il suffit d'ajouter d'autres <em>UrlControllerMapper()</em> dans le tableau. Il est préférable d'avoir des connaissances en regex pour définir au mieux les urls.<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">//Insérer le copyright ici</span>
<a href="http://www.php.net/define"><span style="color: #0000FF; font-weight: bold;">define</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'PATH_TO_ROOT'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'..'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">require_once</span> PATH_TO_ROOT <span style="color: #8000FF;">.</span> <span style="color: #808080;">'/kernel/init.php'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$url_controller_mappers</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
<span style="color: #008000; font-style: italic;">//Admin</span>
<span style="color: #0000FF; font-weight: bold;">new</span> UrlControllerMapper<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'AdminCalendarConfigController'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'`^/admin(?:/config)?/?$`'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">,</span>
<span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
DispatchManager<span style="color: #8000FF;">::</span><span style="color: #000000;">dispatch</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$url_controller_mappers</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span>
&nbsp;</pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-les-images-du-module">Les images du module</h2><br />

<br />
<br />
<br />
<br />
<br />
Deux images doivent être placées à la racine de votre module :<br />
<br />
[list]<br />
<br />
[*] <strong>ModuleName_mini.png</strong> qui doit être une image de 16 pixels de large et de long.<br />
<br />
[*] <strong>ModuleName.png</strong> qui doit être une image de 32 pixels de large et de long.<br />
<br />
ModuleName étant le nom du dossier principal de votre module.<br />
<br />
<span class="message-helper bgc success">A ce stade là, votre module sera visible sur la page d'ajout d'un module dans l'administration.</span>]]></description>
                <pubDate>Sun, 30 Jun 2024 18:18:08 +0200</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Créer vos pages]]></title>
                <link>https://www.phpboost.com/wiki/creer-vos-pages</link>
                <guid>https://www.phpboost.com/wiki/creer-vos-pages</guid>
                <description><![CDATA[Si vous êtes familier avec la <a href="https://fr.wikipedia.org/wiki/Programmation orientée objet" class="wikipedia-link offload">Programmation orientée objet</a> et le modèle <a href="https://fr.wikipedia.org/wiki/MVC" class="wikipedia-link offload">MVC</a> vous ne devriez pas avoir beaucoup de problèmes pour créer vos pages.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-le-fichier-index-php">Le fichier index.php</h2><br />
<br />
<br />
Le fichier index.php devra être créé à la racine de votre module. C'est ce fichier qui va vous permettre d'utiliser tel et tel Contrôleur selon l'url.<br />
<br />
Voici un exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">/*##################################################
 *                                 index.php
 *                            -------------------
 *   begin                : September 06, 2012
 *   copyright            : (C) 2012 Kévin MASSY
 *   email                : kevin.massy@phpboost.com
 *
 *
 ###################################################
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/</span>
<a href="http://www.php.net/define"><span style="color: #0000FF; font-weight: bold;">define</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'PATH_TO_ROOT'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'..'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">require_once</span> PATH_TO_ROOT <span style="color: #8000FF;">.</span> <span style="color: #808080;">'/kernel/init.php'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$url_controller_mappers</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
    <span style="color: #0000FF; font-weight: bold;">new</span> UrlControllerMapper<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'MyModuleAdminController'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'`^/admin/?$`'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">,</span>
        <span style="color: #008000; font-style: italic;">//Contrôleur exécuté lorsqu'il n'y a pas de paramètre</span>
    <span style="color: #0000FF; font-weight: bold;">new</span> UrlControllerMapper<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'MyModuleHomeController'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'`^/?$`'</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
DispatchManager<span style="color: #8000FF;">::</span><span style="color: #000000;">dispatch</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$url_controller_mappers</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div><br />
<br />
Lorsque vous allez accéder à votre module avec cette url <em>http://localhost/my_module/?url=/admin</em>, la classe DispatchManager va exécuter le Contrôleur MyModuleAdminController (Lorsque la réécriture des urls est activée, <em>?url=</em> ne sera plus utile).<br />
<br />
Vous pouvez également gérer vos paramètres, par exemple, dans le cas où vous souhaitez supprimer une news, il vous faudra transmettre l'identifiant de la news.<br />
<br />
Exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">/*##################################################
 *                                 index.php
 *                            -------------------
 *   begin                : September 06, 2012
 *   copyright            : (C) 2012 Kévin MASSY
 *   email                : kevin.massy@phpboost.com
 *
 *
 ###################################################
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/</span>
<a href="http://www.php.net/define"><span style="color: #0000FF; font-weight: bold;">define</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'PATH_TO_ROOT'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'..'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #0000FF; font-weight: bold;">require_once</span> PATH_TO_ROOT <span style="color: #8000FF;">.</span> <span style="color: #808080;">'/kernel/init.php'</span><span style="color: #8000FF;">;</span>
<span style="color: #000080;">$url_controller_mappers</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
    <span style="color: #0000FF; font-weight: bold;">new</span> UrlControllerMapper<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'MyModuleAdminController'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'`^/admin/?$`'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">,</span>
        <span style="color: #008000; font-style: italic;">//Contrôleur exécuté lorsqu'il n'y a pas de paramètre</span>
    <span style="color: #0000FF; font-weight: bold;">new</span> UrlControllerMapper<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'MyModuleHomeController'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'`^/?$`'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">,</span>
        <span style="color: #008000; font-style: italic;">//Contrôleur exécuté avec l'url /my_module/?url/edit/2</span>
        <span style="color: #0000FF; font-weight: bold;">new</span> UrlControllerMapper<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'EditNewsController'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'`^/edit/([0-9]+)?/?$`'</span><span style="color: #8000FF;">,</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'identifier'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
DispatchManager<span style="color: #8000FF;">::</span><span style="color: #000000;">dispatch</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$url_controller_mappers</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div><br />
<br />
Il vous faudra quelques notions de <a href="https://fr.wikipedia.org/wiki/Regex" class="wikipedia-link offload">Regex</a> pour mettre en place la gestion des paramètres.<br />
<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-les-controleurs">Les Contrôleurs</h2><br />
<br />
<br />
Veuillez d'abord, pour une meilleure clarté du module, créer un dossier <em>controllers</em> à la racine de votre site.<br />
<br />
Créer ensuite un fichier et une classe, par exemple MyModuleHomeController. La classe doit être une classe fille de ModuleController ou AdminModuleController (selon si c'est un module à exécuter dans l'administration ou sur le site).<br />
<br />
Une fonction est obligatoire dans cette classe :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> execute<span style="color: #8000FF;">&#40;</span>HTTPRequestCustom <span style="color: #000080;">$request</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
    <span style="color: #8000FF;">&#125;</span></pre></pre></div></div><br />
<br />
Elle devra retourner une <em>Response</em> :<br />
<br />
- <em>SiteDisplayResponse</em> si vous souhaitez afficher votre page avec le design du site<br />
- <em>SiteNodisplayResponse</em> si vous souhaitez afficher votre page sans le design du site<br />
- <em>AdminMenuDisplayResponse</em> si vous souhaitez afficher votre page avec le design de l'administration et un menu à gauche pour les différentes pages de votre module<br />
- <em>AdminDisplayResponse</em> si vous souhaitez afficher votre page avec le design de l'administration sans le menu de gauche<br />
- <em>AdminNodisplayResponse</em> si vous souhaitez afficher votre page sans le design de l'administration<br />
<br />
La <em>Response</em> ne se charge que de la vue (ce que vous voyez).<br />
<br />
Vous devez donc lui donner en paramètre une vue que vous allez afficher dans votre module (objet <em>Template</em>).<br />
<br />
Exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">/*##################################################
 *                         MyModuleHomeController.class.php
 *                            -------------------
 *   begin                : September 06, 2012
 *   copyright            : (C) 2012 Kévin MASSY
 *   email                : kevin.massy@phpboost.com
 *
 *
 ###################################################
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/</span>
<span style="color: #0000FF; font-weight: bold;">class</span> MyModuleHomeController <span style="color: #0000FF; font-weight: bold;">extends</span> ModuleController
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> execute<span style="color: #8000FF;">&#40;</span>HTTPRequestCustom <span style="color: #000080;">$request</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #000080;">$tpl</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> StringTemplate<span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Voici le page d\'accueil de mon module!'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">build_response</span><span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$tpl</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
    <span style="color: #0000FF; font-weight: bold;">private</span> <span style="color: #0000FF; font-weight: bold;">function</span> build_response<span style="color: #8000FF;">&#40;</span>View <span style="color: #000080;">$view</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #000080;">$response</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> SiteDisplayResponse<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$view</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
        <span style="color: #000080;">$response</span><span style="color: #8000FF;">-></span><span style="color: #000000;">get_graphical_environment</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">-></span><span style="color: #000000;">set_page_title</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Mon premier module !'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #000080;">$response</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div><br />
<br />
<h3 class="formatter-title wiki-paragraph-3" id="paragraph-cas-particulier-jsonresponse">Cas particulier : JSONResponse</h3><br />
<br />
<br />
Vous avez également la possibilité de renvoyer des données en JSON dans un contrôleur vous permettant de communiquer plus facilement entre différents langages de programmation comme le Javascript par exemple.<br />
<br />
Exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #008000; font-style: italic;">/*##################################################
 *                         MyModuleJSONController.class.php
 *                            -------------------
 *   begin                : September 06, 2012
 *   copyright            : (C) 2012 Kévin MASSY
 *   email                : kevin.massy@phpboost.com
 *
 *
 ###################################################
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/</span>
<span style="color: #0000FF; font-weight: bold;">class</span> MyModuleJSONController <span style="color: #0000FF; font-weight: bold;">extends</span> ModuleController
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> execute<span style="color: #8000FF;">&#40;</span>HTTPRequestCustom <span style="color: #000080;">$request</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #000080;">$data</span> <span style="color: #8000FF;">=</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'Vos données'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #0000FF; font-weight: bold;">new</span> JSONResponse<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$data</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div>]]></description>
                <pubDate>Tue, 15 Jan 2019 21:56:17 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Mise en place du ModuleSetup]]></title>
                <link>https://www.phpboost.com/wiki/mise-en-place-du-modulesetup</link>
                <guid>https://www.phpboost.com/wiki/mise-en-place-du-modulesetup</guid>
                <description><![CDATA[<br />
Le <em>ModuleSetup</em> vous permet de personnaliser l'installation, les mises à jour ou la désinstallation de votre module.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-le-fonctionnement">Le fonctionnement</h2><br />

<br />
Il faut créer un fichier <strong>LeNomDeVotreModuleSetup.class.php</strong> qui contiendra une classe du même nom.<br />
<br />
Cette classe est une <strong>classe fille de DefaultModuleSetup</strong> et devra contenir une fonction install() et uninstall().<br />
<br />
Pour plus de clarté dans votre module, créez un dossier <em>phpboost</em> à sa racine et placez-y votre classe.<br />
<br />
Exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">class</span> MonModuleSetup <span style="color: #0000FF; font-weight: bold;">extends</span> DefaultModuleSetup
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> install<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
&nbsp;
    <span style="color: #8000FF;">&#125;</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> uninstall<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
&nbsp;
    <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div><br />
<br />
A chaque installation et à chaque désinstallation ce fichier sera appelé. C'est donc à l'intérieur des deux fonctions que vous allez exécuter les différentes tâches que vous souhaitez faire. Créer des tables, les supprimer, etc.<br />
<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-la-mise-a-jour-d-un-module">La mise à jour d'un module</h2><br />

<br />
Vous allez également pouvoir faire les mises à jour de votre module à travers ce fichier en ajoutant une fonction upgrade() :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> upgrade<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$installed_version</span><span style="color: #8000FF;">&#41;</span>
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">return</span> <span style="">null</span><span style="color: #8000FF;">;</span>
<span style="color: #8000FF;">&#125;</span></pre></pre></div></div><br />
<br />
De cette manière, l'utilisateur qui mettra à jour le module à travers l'administration ne perdra pas ses données en cas de changement au niveau des tables ou autres. C'est maintenant à vous de procéder à la conversion des différents éléments.<br />
<br />
L'argument passé en paramètre renvoie le numéro de version installée sur le serveur de l'utilisateur. En valeur de retour, il faudra renvoyer le nouveau numéro de version. Si la fonction ne retourne rien ou est nulle alors la page de mise à jour renverra une erreur à l'utilisateur.<br />
<br />
Exemple 1 : Mise à jour de la version du module.<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> upgrade<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$installed_version</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#125;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #808080;">'5.1.0'</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span></pre></pre></div></div><br />
<br />
Exemple 2 : Mise à jour de la version du module et suppression d'un fichier.<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> upgrade<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$installed_version</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #000080;">$file</span> <span style="color: #8000FF;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span> <a href="http://www.php.net/file"><span style="color: #0000FF; font-weight: bold;">File</span></a><span style="color: #8000FF;">&#40;</span>Url<span style="color: #8000FF;">::</span><span style="color: #000000;">to_rel</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'/nommodule/controllers/NommoduleController.class.php'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
        <span style="color: #000080;">$file</span><span style="color: #8000FF;">-></span><span style="color: #000000;">delete</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #808080;">'5.1.0'</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>  </pre></pre></div></div><br />
<br />
La méthode upgrade () vous permet donc de mettre à jour votre version de module ainsi que d'effectuer toutes vos modifications au niveau des fichiers ou de votre base de données. Il suffit de placer l'ensemble de vos fonctions à l'intérieur de la méthode.]]></description>
                <pubDate>Fri, 27 Oct 2017 18:50:32 +0200</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Créer une configuration pour votre module]]></title>
                <link>https://www.phpboost.com/wiki/creer-une-configuration-pour-votre-module</link>
                <guid>https://www.phpboost.com/wiki/creer-une-configuration-pour-votre-module</guid>
                <description><![CDATA[PHPBoost intègre une solution complète de gestion de configuration. Celle-ci est stockée automatiquement dans la Base de données, mais crée également un fichier de cache (bien plus rapide pour un accès très fréquent que la recherche en base de données).  Selon la configuration du serveur, elle peut être stockée sur le disque dur ou dans la mémoire RAM du serveur (encore plus rapide).<br />
<br />
Nous allons voir comment utiliser ces outils mis en place par le framework.<br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-mise-en-place">Mise en place</h2><br />
<br />
Il va falloir créer une classe, par exemple <em>MyModuleConfig</em>. Elle doit être crée dans un fichier : <em>MyModuleConfig.class.php</em><br />
<br />
Elle devra être une classe fille de <em>AbstractConfigData</em>. Voici un exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">class</span> MyModuleConfig <span style="color: #0000FF; font-weight: bold;">extends</span> AbstractConfigData
<span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">//Renvoie le nom de votre module</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> get_name<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
                <span style="color: #008000; font-style: italic;">//Retourne la valeur contenue dans le tableau de la configuration avec comme clé = name</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">get_property</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'name'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic;">//Modifie le nom de votre module</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> set_name<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$name</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
                <span style="color: #008000; font-style: italic;">// Modifie la configuration avec comme clé = name</span>
        <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">set_property</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'name'</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$name</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> get_default_values<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// Tableau de la configuration par défaut</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
            <span style="color: #808080;">'name'</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Nom de votre module'</span>
        <span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">/**
     * Returns the configuration.
     * @return MyModuleConfig
     */</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> static <span style="color: #0000FF; font-weight: bold;">function</span> load<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> ConfigManager<span style="color: #8000FF;">::</span><span style="color: #000000;">load</span><span style="color: #8000FF;">&#40;</span><span style="">__CLASS__</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'my-module'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'config'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">/**
     * Saves the configuration in the database. Has it become persistent.
     */</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> static <span style="color: #0000FF; font-weight: bold;">function</span> save<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        ConfigManager<span style="color: #8000FF;">::</span><span style="color: #000000;">save</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'my-module'</span><span style="color: #8000FF;">,</span> <span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000000;">load</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'config'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-utilisation">Utilisation</h2><br />
<br />
Pour récupérer la configuration de votre module :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">//Renvoie l'objet MyModuleConfig avec la configuration (par défaut si besoin)</span>
<span style="color: #000080;">$config</span> <span style="color: #8000FF;">=</span> MyModuleConfig<span style="color: #8000FF;">::</span><span style="color: #000000;">load</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// Affiche le nom de votre module</span>
<span style="color: #0000FF; font-weight: bold;">echo</span> <span style="color: #000080;">$config</span><span style="color: #8000FF;">-></span><span style="color: #000000;">get_name</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span></pre></pre></div></div><br />
<br />
Pour modifier la configuration :<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #008000; font-style: italic;">//Renvoie l'objet MyModuleConfig avec la configuration (par défaut si besoin)</span>
<span style="color: #000080;">$config</span> <span style="color: #8000FF;">=</span> MyModuleConfig<span style="color: #8000FF;">::</span><span style="color: #000000;">load</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// On met en place la nouvelle valeur</span>
<span style="color: #000080;">$config</span><span style="color: #8000FF;">-></span><span style="color: #000000;">set_name</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'ma nouvelle valeur'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">//On sauvegarde la config</span>
MyModuleConfig<span style="color: #8000FF;">::</span><span style="color: #000000;">save</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span></pre></pre></div></div><br />
<br />
<h2 class="formatter-title wiki-paragraph-2" id="paragraph-conseils">Conseils</h2><br />
<br />
Pour une meilleure qualité du code, les clés des tableaux doivent être stockées dans des constantes.<br />
<br />
Exemple :<br />
<br />
<div class="formatter-container formatter-code code-PHP"><span class="formatter-title">Code PHP : </span><div class="formatter-content"><pre style="display:inline;"><pre class="php" style="font-family:monospace;"><span style="color: #FF0000; font-weight: normal;"><?php</span>
<span style="color: #0000FF; font-weight: bold;">class</span> MyModuleConfig <span style="color: #0000FF; font-weight: bold;">extends</span> AbstractConfigData
<span style="color: #8000FF;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">const</span> NAME <span style="color: #8000FF;">=</span> <span style="color: #808080;">'name'</span><span style="color: #8000FF;">;</span>
&nbsp;
       <span style="color: #008000; font-style: italic;">//Renvoie le nom de votre module</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> get_name<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">get_property</span><span style="color: #8000FF;">&#40;</span><span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000000;">NAME</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
        <span style="color: #008000; font-style: italic;">//Modifie le nom de votre module</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> set_name<span style="color: #8000FF;">&#40;</span><span style="color: #000080;">$name</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #000080;">$this</span><span style="color: #8000FF;">-></span><span style="color: #000000;">set_property</span><span style="color: #8000FF;">&#40;</span><span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000000;">NAME</span><span style="color: #8000FF;">,</span> <span style="color: #000080;">$name</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #0000FF; font-weight: bold;">public</span> <span style="color: #0000FF; font-weight: bold;">function</span> get_default_values<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #008000; font-style: italic;">// Tableau de la configuration par défaut</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> <a href="http://www.php.net/array"><span style="color: #0000FF; font-weight: bold;">array</span></a><span style="color: #8000FF;">&#40;</span>
            <span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000000;">NAME</span> <span style="color: #8000FF;">=></span> <span style="color: #808080;">'Nom de votre module'</span>
        <span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">/**
     * Returns the configuration.
     * @return MyModuleConfig
     */</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> static <span style="color: #0000FF; font-weight: bold;">function</span> load<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        <span style="color: #0000FF; font-weight: bold;">return</span> ConfigManager<span style="color: #8000FF;">::</span><span style="color: #000000;">load</span><span style="color: #8000FF;">&#40;</span><span style="">__CLASS__</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'my-module'</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'config'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">/**
     * Saves the configuration in the database. Has it become persistent.
     */</span>
    <span style="color: #0000FF; font-weight: bold;">public</span> static <span style="color: #0000FF; font-weight: bold;">function</span> save<span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span>
    <span style="color: #8000FF;">&#123;</span>
        ConfigManager<span style="color: #8000FF;">::</span><span style="color: #000000;">save</span><span style="color: #8000FF;">&#40;</span><span style="color: #808080;">'my-module'</span><span style="color: #8000FF;">,</span> <span style="color: #0000FF; font-weight: bold;">self</span><span style="color: #8000FF;">::</span><span style="color: #000000;">load</span><span style="color: #8000FF;">&#40;</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">,</span> <span style="color: #808080;">'config'</span><span style="color: #8000FF;">&#41;</span><span style="color: #8000FF;">;</span>
    <span style="color: #8000FF;">&#125;</span>
<span style="color: #8000FF;">&#125;</span>
<span style="color: #FF0000; font-weight: normal;">?></span></pre></pre></div></div>]]></description>
                <pubDate>Sat, 24 Nov 2012 09:53:38 +0100</pubDate>
                
            </item>
		
            <item>
                <title><![CDATA[Créer un module]]></title>
                <link>https://www.phpboost.com/wiki/creer-un-module</link>
                <guid>https://www.phpboost.com/wiki/creer-un-module</guid>
                <description><![CDATA[Créer un module]]></description>
                <pubDate>Fri, 24 Aug 2012 17:28:01 +0200</pubDate>
                
            </item>
		
	</channel>
</rss>
