J3.x

Difference between revisions of "Developing an MVC Component/Adding an install-uninstall-update script file/fr"

From Joomla! Documentation

< J3.x:Developing an MVC Component
(Updating to match new version of source page)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
<noinclude><languages /></noinclude>
 
<noinclude><languages /></noinclude>
{{review}}
 
 
{{:J3.1:Developing an MVC Component/fr}}
 
{{:J3.1:Developing an MVC Component/fr}}
 
==Introduction==
 
==Introduction==
 
Ce didacticiel fait partie de la série de didacticiels sur le  [[S:MyLanguage/J3.2:Developing an MVC Component|Développement d'un Composant MVC pour Joomla! 3.x]]. Vous êtes invité à lire les articles précédents de cette série avant de lire celui-ci.
 
Ce didacticiel fait partie de la série de didacticiels sur le  [[S:MyLanguage/J3.2:Developing an MVC Component|Développement d'un Composant MVC pour Joomla! 3.x]]. Vous êtes invité à lire les articles précédents de cette série avant de lire celui-ci.
 +
 +
Vous pouvez visualiser une vidéo associée à cette étape sur [https://youtu.be/uLaXYCuVOx8 un aperçu du processus d'installation de Joomlaǃ] (en anglais).
 +
 +
{{#widget:YouTube|id=uLaXYCuVOx8}}
  
 
== Créer le fichier de script de l'extension ==
 
== Créer le fichier de script de l'extension ==
Line 19: Line 22:
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
// No direct access to this file
 +
defined('_JEXEC') or die('Restricted access');
 +
 
/**
 
/**
 +
* Script file of HelloWorld component.
 +
*
 +
* The name of this class is dependent on the component being installed.
 +
* The class name should have the component's name, directly followed by
 +
* the text InstallerScript (ex:. com_helloWorldInstallerScript).
 +
*
 +
* This class will be called by Joomla!'s installer, if specified in your component's
 +
* manifest file, and is used for custom automation actions in its installation process.
 +
*
 +
* In order to use this automation script, you should reference it in your component's
 +
* manifest file as follows:
 +
* <scriptfile>script.php</scriptfile>
 +
*
 
  * @package    Joomla.Administrator
 
  * @package    Joomla.Administrator
 
  * @subpackage  com_helloworld
 
  * @subpackage  com_helloworld
 
  *
 
  *
  * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
+
  * @copyright  Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
 
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
 
  */
 
  */
 +
class com_helloWorldInstallerScript
 +
{
 +
    /**
 +
    * This method is called after a component is installed.
 +
    *
 +
    * @param  \stdClass $parent - Parent object calling this method.
 +
    *
 +
    * @return void
 +
    */
 +
    public function install($parent)
 +
    {
 +
        $parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
 +
    }
  
// No direct access to this file
+
    /**
defined('_JEXEC') or die('Restricted access');
+
    * This method is called after a component is uninstalled.
+
    *
/**
+
    * @param  \stdClass $parent - Parent object calling this method.
* Script file of HelloWorld component
+
    *
*/
+
    * @return void
class Com_helloWorldInstallerScript
+
    */
{
+
    public function uninstall($parent)  
/**
+
    {
* method to install the component
+
        echo '<p>' . JText::_('COM_HELLOWORLD_UNINSTALL_TEXT') . '</p>';
*
+
    }
* @return void
+
 
*/
+
    /**
function install($parent)
+
    * This method is called after a component is updated.
{
+
    *
// $parent is the class calling this method
+
    * @param  \stdClass $parent - Parent object calling object.
$parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
+
    *
}
+
    * @return void
+
    */
/**
+
    public function update($parent)  
* method to uninstall the component
+
    {
*
+
        echo '<p>' . JText::sprintf('COM_HELLOWORLD_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>';
* @return void
+
    }
*/
+
 
function uninstall($parent)  
+
    /**
{
+
    * Runs just before any installation action is performed on the component.
echo '<p>' . JText::_('COM_HELLOWORLD_UNINSTALL_TEXT') . '</p>';
+
    * Verifications and pre-requisites should run in this function.
}
+
    *
+
    * @param  string    $type  - Type of PreFlight action. Possible values are:
/**
+
    *                          - * install
* method to update the component
+
    *                          - * update
*
+
    *                          - * discover_install
* @return void
+
    * @param  \stdClass $parent - Parent object calling object.
*/
+
    *
function update($parent)  
+
    * @return void
{
+
    */
// $parent is the class calling this method
+
    public function preflight($type, $parent)  
echo '<p>' . JText::sprintf('COM_HELLOWORLD_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>';
+
    {
}
+
        echo '<p>' . JText::_('COM_HELLOWORLD_PREFLIGHT_' . $type . '_TEXT') . '</p>';
+
    }
/**
+
 
* method to run before an install/update/uninstall method
+
    /**
*
+
    * Runs right after any installation action is performed on the component.
* @return void
+
    *
*/
+
    * @param  string    $type  - Type of PostFlight action. Possible values are:
function preflight($type, $parent)  
+
    *                          - * install
{
+
    *                          - * update
// $parent is the class calling this method
+
    *                          - * discover_install
// $type is the type of change (install, update or discover_install)
+
    * @param  \stdClass $parent - Parent object calling object.
echo '<p>' . JText::_('COM_HELLOWORLD_PREFLIGHT_' . $type . '_TEXT') . '</p>';
+
    *
}
+
    * @return void
+
    */
/**
+
    function postflight($type, $parent)  
* method to run after an install/update/uninstall method
+
    {
*
+
        echo '<p>' . JText::_('COM_HELLOWORLD_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
* @return void
+
    }
*/
 
function postflight($type, $parent)  
 
{
 
// $parent is the class calling this method
 
// $type is the type of change (install, update or discover_install)
 
echo '<p>' . JText::_('COM_HELLOWORLD_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
 
}
 
 
}
 
}
 
</source>
 
</source>
Line 102: Line 127:
 
<source lang="ini" highlight="10,12-22">
 
<source lang="ini" highlight="10,12-22">
 
; Joomla! Project
 
; Joomla! Project
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
+
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
 
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 
; Note : All ini files need to be saved as UTF-8
 
; Note : All ini files need to be saved as UTF-8
Line 112: Line 137:
 
COM_HELLOWORLD_INSTALL_TEXT="HelloWorld Install script"
 
COM_HELLOWORLD_INSTALL_TEXT="HelloWorld Install script"
 
COM_HELLOWORLD_MENU="Hello World!"
 
COM_HELLOWORLD_MENU="Hello World!"
COM_HELLOWORLD_POSTFLIGHT_DISCOVER_INSTALL_TEXT="HelloWorld postlight discover install script"
+
COM_HELLOWORLD_POSTFLIGHT_DISCOVER_INSTALL_TEXT="HelloWorld postflight discover install script"
 
COM_HELLOWORLD_POSTFLIGHT_INSTALL_TEXT="HelloWorld postflight install script"
 
COM_HELLOWORLD_POSTFLIGHT_INSTALL_TEXT="HelloWorld postflight install script"
 
COM_HELLOWORLD_POSTFLIGHT_UNINSTALL_TEXT="HelloWorld postflight uninstall script"
 
COM_HELLOWORLD_POSTFLIGHT_UNINSTALL_TEXT="HelloWorld postflight uninstall script"
Line 142: Line 167:
 
== Empaqueter le composant ==
 
== Empaqueter le composant ==
  
Contenu de votre répertoire de code
+
Contenu de votre répertoire de code. Chaque lien ci-dessous vous emmène vers l'étape du didacticiel qui contient la dernière version du code source de ce fichier.
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#helloworld.xml|helloworld.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding an install-uninstall-update script file#helloworld.xml|helloworld.xml]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding an install-uninstall-update script file#script.php|script.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding an install-uninstall-update script file#script.php|script.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]''
Line 150: Line 175:
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_configuration#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_configuration#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#site/models/helloworld.php|site/models/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_configuration#site/models/helloworld.php|site/models/helloworld.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]''
 
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding language management#site.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]''
 
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding language management#site.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/helloworld.php|admin/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/helloworld.php|admin/helloworld.php]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_configuration#admin/config.xml|admin/config.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/config.xml|admin/config.xml]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/access.xml|admin/access.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/access.xml|admin/access.xml]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/helpers/helloworld.php|admin/helpers/helloworld.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/helpers/helloworld.php|admin/helpers/helloworld.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/helpers/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/helpers/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
+
* ''[[J3.2:Developing_an_MVC_Component/Adding_ACL#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/sql/updates/mysql/0.0.12.sql|admin/sql/updates/mysql/0.0.12.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/sql/updates/mysql/0.0.12.sql|admin/sql/updates/mysql/0.0.12.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_configuration#admin/sql/updates/mysql/0.0.13.sql|admin/sql/updates/mysql/0.0.13.sql]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_configuration#admin/sql/updates/mysql/0.0.13.sql|admin/sql/updates/mysql/0.0.13.sql]]''
Line 178: Line 203:
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/models/helloworlds.php|admin/models/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/models/helloworld.php|admin/models/helloworld.php]]''
 +
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding decorations to the backend#admin/models/forms/filter_helloworlds.xml|admin/models/forms/filter_helloworlds.xml]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/forms/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/forms/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_verifications#admin/models/forms/helloworld.js|admin/models/forms/helloworld.js]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_verifications#admin/models/forms/helloworld.js|admin/models/forms/helloworld.js]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/models/forms/helloworld.xml|admin/models/forms/helloworld.xml]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_verifications#admin/models/rules/greeting.php|admin/models/rules/greeting.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_verifications#admin/models/rules/greeting.php|admin/models/rules/greeting.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/rules/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/rules/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/controllers/helloworld.php|admin/controllers/helloworld.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/controllers/helloworlds.php|admin/controllers/helloworlds.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/controllers/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/controllers/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/views/helloworld/view.html.php|admin/views/helloworld/view.html.php]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_backend_actions#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworld/tmpl/index.html]]''
 +
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/views/helloworld/tmpl/edit.php|admin/views/helloworld/tmpl/edit.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_verifications#admin/views/helloworld/submitbutton.js|admin/views/helloworld/submitbutton.js]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_verifications#admin/views/helloworld/submitbutton.js|admin/views/helloworld/submitbutton.js]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_categories#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Adding_ACL#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/en-GB/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/en-GB/index.html]]''
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
+
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding_ACL#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding language management#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
+
* ''[[S:MyLanguage/J3.x:Developing an MVC Component/Adding an install-uninstall-update script file#admin.2Flanguage.2Fen-GB.2Fen-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|media/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|media/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|media/images/index.html]]''
 
* ''[[S:MyLanguage/J3.2:Developing_an_MVC_Component/Developing_a_Basic_Component#index.html|media/images/index.html]]''
Line 209: Line 236:
 
* ''[[S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/tux-48x48.png]]''
 
* ''[[S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding_decorations_to_the_backend#Adding_some_icons|media/images/tux-48x48.png]]''
  
Créez un fichier compressé de ce répertoire ou téléchargez directement l'[https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-15-adding-an-install-uninstall-update-script-file.zip archive] et installez-le en utilisant le gestionnaire des extensions Joomla. Vous pouvez ajouter un lien de menu pour ce composant à l'aide du gestionnaire de menus dans le backend.
+
Créez un fichier compressé de ce répertoire ou téléchargez directement l'[https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-15-adding-an-install-uninstall-update-script-file.zip archive] et installez-le en utilisant le gestionnaire des extensions Joomla. Vous pouvez ajouter un lien de menu pour ce composant à l'aide du gestionnaire de menus en backend.
  
 
<span id="helloworld.xml">
 
<span id="helloworld.xml">
Line 215: Line 242:
 
<source lang="xml" highlight="13,17-19">
 
<source lang="xml" highlight="13,17-19">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">
+
<extension type="component" version="3.0" method="upgrade">
  
 
<name>COM_HELLOWORLD</name>
 
<name>COM_HELLOWORLD</name>
<!-- The following elements are optional and free of formatting constraints -->
+
<!-- The following elements are optional and free of formatting constraints. -->
<creationDate>February 2015</creationDate>
+
<creationDate>January 2018</creationDate>
 
<author>John Doe</author>
 
<author>John Doe</author>
 
<authorEmail>john.doe@example.org</authorEmail>
 
<authorEmail>john.doe@example.org</authorEmail>
Line 311: Line 338:
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:Scionescire|Scionescire]]
 
*[[User:Scionescire|Scionescire]]
 +
*[[User:Robbiej|Robbie Jackson]]
  
 
<div class="row">  
 
<div class="row">  
 
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding ACL|Préc. : Ajout d'ACL|class=expand success}}</div>
 
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding ACL|Préc. : Ajout d'ACL|class=expand success}}</div>
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Using the language filter facility|Suiv. : Utilisation du filtre de langues|class=expand}}</div>
+
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Adding a front-end form|Suiv. : Ajout d'un formulaire de frontend|class=expand}}</div>
 
</div>
 
</div>
 
__NOTOC__
 
__NOTOC__
 
<noinclude>
 
<noinclude>
[[Category:Joomla! 3.x/fr|Joomla! 3.x]]
+
[[Category:Joomla! 3.x{{#translation:}}]]
[[Category:Joomla! 3.0/fr|Joomla! 3.0]]
+
[[Category:Joomla! 3.0{{#translation:}}]]
[[Category:Joomla! 3.1/fr|Joomla! 3.1]]
+
[[Category:Joomla! 3.1{{#translation:}}]]
[[Category:Joomla! 3.2/fr|Joomla! 3.2]]
+
[[Category:Joomla! 3.2{{#translation:}}]]
[[Category:Joomla! 3.3/fr|Joomla! 3.3]]
+
[[Category:Joomla! 3.3{{#translation:}}]]
[[Category:Joomla! 3.4/fr|Joomla! 3.4]]
+
[[Category:Joomla! 3.4{{#translation:}}]]
[[Category:Beginner Development/fr|Développement pour débutants]]
+
[[Category:Beginner Development{{#translation:}}]]
[[Category:Component Development/fr|Développement de composants]]
+
[[Category:Component Development{{#translation:}}]]
[[Category:Tutorials/fr|Didacticiels]]
+
[[Category:Tutorials{{#translation:}}]]
[[Category:Tutorials in a Series/fr|Didacticiels en série]]
+
[[Category:Tutorials in a Series{{#translation:}}]]
 
</noinclude>
 
</noinclude>

Latest revision as of 16:34, 7 July 2019

Other languages:
English • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎
Joomla! 
3.x
Didacticiel
Développement d'un composant MVC

Ajout d'une requête de variable dans le type de menu

Utilisation de la base de données

Backend de base

Ajout de la gestion des langues

Ajout d'actions en backend

Ajout de décorations pour le backend

Ajout de vérifications

Ajout de catégories

Ajout de configuration

  1. Ajout d'ACL

Ajout d'un fichier script installation/désinstallation/mise à jour

Ajout d'un formulaire de frontend

  1. Ajout d'une image
  2. Ajout d'un plan
  3. Ajout d'AJAX
  4. Ajout d'un alias

Utilisation du filtre de langues

  1. Ajouter une fenêtre modale
  2. Ajout d'associations
  3. Ajout de Checkout
  4. Ajout d'un filtre
  5. Ajout de niveaux
  6. Ajout de versions
  7. Ajout de tags
  8. Ajout d'accès
  9. Ajout d'un processus de traitement
  10. Ajout d'un cache
  11. Ajout d'un fil d'actualité

Ajout d'un serveur de mise à jour

  1. Adding Custom Fields
  2. Upgrading to Joomla4



Ceci est une série qui regroupe plusieurs articles pour devenir un didacticiel sur la façon de développer un Composant pour Joomla! Joomla 3.x suivant le principe Modèle-Vue-Contrôleur.

Commencez avec l'introduction, et naviguez dans les articles de cette série soit à l'aide des boutons de navigation en bas des articles, soit grâce au menu de droite : Les articles de cette série.



Introduction

Ce didacticiel fait partie de la série de didacticiels sur le Développement d'un Composant MVC pour Joomla! 3.x. Vous êtes invité à lire les articles précédents de cette série avant de lire celui-ci.

Vous pouvez visualiser une vidéo associée à cette étape sur un aperçu du processus d'installation de Joomlaǃ (en anglais).

Créer le fichier de script de l'extension

L'installation, la mise à jour et la désinstallation d'un module peuvent nécessiter des opérations supplémentaires qui ne peuvent être réalisées par les opérations de base décrites dans le fichier XML principal. Joomla! propose une nouvelle approche pour résoudre ce problème. Elle consiste en l'utilisation d'un fichier de script php contenant une classe utilisant cinq méthodes :

  • preflight, exécuté avant install et update
  • install
  • update
  • uninstall
  • postflight, exécuté après install et update

L'écriture d'un script d'extension consiste à déclarer une classe dont le nom est com_NomduComposantInstallerScript contenant ces 5 méthodes.

script.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

/**
 * Script file of HelloWorld component.
 *
 * The name of this class is dependent on the component being installed.
 * The class name should have the component's name, directly followed by
 * the text InstallerScript (ex:. com_helloWorldInstallerScript).
 *
 * This class will be called by Joomla!'s installer, if specified in your component's
 * manifest file, and is used for custom automation actions in its installation process.
 *
 * In order to use this automation script, you should reference it in your component's
 * manifest file as follows:
 * <scriptfile>script.php</scriptfile>
 *
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
class com_helloWorldInstallerScript
{
    /**
     * This method is called after a component is installed.
     *
     * @param  \stdClass $parent - Parent object calling this method.
     *
     * @return void
     */
    public function install($parent) 
    {
        $parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
    }

    /**
     * This method is called after a component is uninstalled.
     *
     * @param  \stdClass $parent - Parent object calling this method.
     *
     * @return void
     */
    public function uninstall($parent) 
    {
        echo '<p>' . JText::_('COM_HELLOWORLD_UNINSTALL_TEXT') . '</p>';
    }

    /**
     * This method is called after a component is updated.
     *
     * @param  \stdClass $parent - Parent object calling object.
     *
     * @return void
     */
    public function update($parent) 
    {
        echo '<p>' . JText::sprintf('COM_HELLOWORLD_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>';
    }

    /**
     * Runs just before any installation action is performed on the component.
     * Verifications and pre-requisites should run in this function.
     *
     * @param  string    $type   - Type of PreFlight action. Possible values are:
     *                           - * install
     *                           - * update
     *                           - * discover_install
     * @param  \stdClass $parent - Parent object calling object.
     *
     * @return void
     */
    public function preflight($type, $parent) 
    {
        echo '<p>' . JText::_('COM_HELLOWORLD_PREFLIGHT_' . $type . '_TEXT') . '</p>';
    }

    /**
     * Runs right after any installation action is performed on the component.
     *
     * @param  string    $type   - Type of PostFlight action. Possible values are:
     *                           - * install
     *                           - * update
     *                           - * discover_install
     * @param  \stdClass $parent - Parent object calling object.
     *
     * @return void
     */
    function postflight($type, $parent) 
    {
        echo '<p>' . JText::_('COM_HELLOWORLD_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
    }
}

Ce fichier de script va rediriger l'utilisateur vers le composant com_helloworld lorsqu'il est installé et va afficher les messages lors de sa mise à jour ou de sa désinstallation. Dans la méthode de mise à jour, nous affichons la nouvelle version à l'aide de $parent->get('manifest')->version.

Ajouter des clés de langue

admin/language/en-GB/en-GB.com_helloworld.sys.ini

; Joomla! Project
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_HELLOWORLD="Hello World!"
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE="Hello World"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
COM_HELLOWORLD_INSTALL_TEXT="HelloWorld Install script"
COM_HELLOWORLD_MENU="Hello World!"
COM_HELLOWORLD_POSTFLIGHT_DISCOVER_INSTALL_TEXT="HelloWorld postflight discover install script"
COM_HELLOWORLD_POSTFLIGHT_INSTALL_TEXT="HelloWorld postflight install script"
COM_HELLOWORLD_POSTFLIGHT_UNINSTALL_TEXT="HelloWorld postflight uninstall script"
COM_HELLOWORLD_POSTFLIGHT_UPDATE_TEXT="HelloWorld postflight update script"
COM_HELLOWORLD_PREFLIGHT_DISCOVER_INSTALL_TEXT="HelloWorld preflight discover install script"
COM_HELLOWORLD_PREFLIGHT_INSTALL_TEXT="HelloWorld preflight install script"
COM_HELLOWORLD_PREFLIGHT_UNINSTALL_TEXT="HelloWorld preflight uninstall script"
COM_HELLOWORLD_PREFLIGHT_UPDATE_TEXT="HelloWorld preflight update script"
COM_HELLOWORLD_UNINSTALL_TEXT="HelloWorld Uninstall script"
COM_HELLOWORLD_UPDATE_TEXT="HelloWorld Update script. HelloWorld now updated to version %s."

Remarque : Si vous souhaitez que ces clés de langue soient utilisées lors de la première installation du composant, le fichier de langues sys.ini doit être stocké dans le dossier du composant (admin/language/en-GB/en-GB.com_helloworld.sys.ini) et le fichier xml Manifest doit contenir une balise folder pour pouvoir copier les langues dans le dossier du composant. Modifiez votre fichier Manifest en conséquence :

                <files folder="admin">
                        <!-- language folder -->
                        <folder>language</folder>
                </files>
 
                <languages folder="admin">
                        <language tag="en-GB">language/en-GB/en-GB.com_helloworld.ini</language>
                        <!-- com_helloworld.sys.ini no longer needed there-->
                </languages>

Empaqueter le composant

Contenu de votre répertoire de code. Chaque lien ci-dessous vous emmène vers l'étape du didacticiel qui contient la dernière version du code source de ce fichier.

Créez un fichier compressé de ce répertoire ou téléchargez directement l'archive et installez-le en utilisant le gestionnaire des extensions Joomla. Vous pouvez ajouter un lien de menu pour ce composant à l'aide du gestionnaire de menus en backend.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints. -->
	<creationDate>January 2018</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<authorUrl>http://www.example.org</authorUrl>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is recorded in the components table -->
	<version>0.0.15</version>
	<!-- The description is optional and defaults to the name -->
	<description>COM_HELLOWORLD_DESCRIPTION</description>

	<!-- Runs on install/uninstall/update; New in 2.5 -->
	<scriptfile>script.php</scriptfile>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>
	<update> <!-- Runs on update; New since J2.5 -->
		<schemas>
			<schemapath type="mysql">sql/updates/mysql</schemapath>
		</schemas>
	</update>

	<!-- Site Main File Copy Section -->
	<!-- Note the folder attribute: This attribute describes the folder
		to copy FROM in the package to install therefore files copied
		in this section are copied from /site/ in the package -->
	<files folder="site">
		<filename>index.html</filename>
		<filename>helloworld.php</filename>
		<filename>controller.php</filename>
		<folder>views</folder>
		<folder>models</folder>
	</files>

        <languages folder="site/language">
		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
        </languages>

	<media destination="com_helloworld" folder="media">
		<filename>index.html</filename>
		<folder>images</folder>
	</media>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld' img="../media/com_helloworld/images/tux-16x16.png">COM_HELLOWORLD_MENU</menu>
		<!-- Administration Main File Copy Section -->
		<!-- Note the folder attribute: This attribute describes the folder
			to copy FROM in the package to install therefore files copied
			in this section are copied from /admin/ in the package -->
		<files folder="admin">
			<!-- Admin Main File Copy Section -->
			<filename>index.html</filename>
			<filename>config.xml</filename>
			<filename>helloworld.php</filename>
			<filename>controller.php</filename>
			<filename>access.xml</filename>
			<!-- SQL files section -->
			<folder>sql</folder>
			<!-- tables files section -->
			<folder>tables</folder>
			<!-- models files section -->
			<folder>models</folder>
			<!-- views files section -->
			<folder>views</folder>
			<!-- controllers files section -->
			<folder>controllers</folder>
			<!-- helpers files section -->
			<folder>helpers</folder>
		</files>
		<languages folder="admin/language">
        		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
		</languages>
	</administration>

</extension>

Contributeurs