Joomla 3.x_component如何打包安装和卸载

来源:互联网 发布:linux beam.smp 编辑:程序博客网 时间:2024/06/01 21:12

本文是component的打包,与component安装和卸载相关的内容。component包内与安装卸载相关的文件就只有两个,script.php和componentname.xml。script.php是安装或卸载时运行的脚本,componentname.xml是指导安装如何进行的和包含哪些安装文件。下面就一步步建一个基本component包,例子的component名为com_example:

(1)example.xml文件,注意的是,每个文件夹下一定要有个index.html,防止目录浏览。

<?xml version="1.0" encoding="utf-8"?><extension type="component" version="3.0" method="upgrade">    <!-- component的基本信息 -->  <name>COM_EXAMPLE</name> <!-- 大写表明该项为多语言翻译项,在language的ini文件中 -->  <author>Laixiang Wen</author>  <version>1.0</version>  <creationDate>Apirl 4, 2013</creationDate>  <copyright>Copyright (C) 2013 Fighting Bull Studio. All rights reserved.</copyright>  <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>  <authorEmail>fightingbull.wen@gmail.com</authorEmail>  <description>COM_EXAMPLE_XML_DESCRIPTION</description>  <!-- 与安装卸载有关的文件 --> <scriptfile>script.php</scriptfile><!-- 安装过程中的高级定制 -->  <install>    <sql>      <file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file> <!-- 数据库中表的创建 -->    </sql>  </install>  <uninstall>    <sql>      <file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file> <!-- 数据库中表的删除 -->    </sql>  </uninstall>   <!--安装中拷贝的文件  --><!-- frontend安装的文件,放到WebRoot/components/com_example下 -->  <files folder="site">    <filename>index.html</filename>    <filename>example.php</filename>    <filename>controller.php</filename>      <folder>models</folder>    <folder>views</folder>    <folder>controllers</folder>    <folder>helpers</folder>  </files>  <languages folder="site">    <language tag="en-GB">language/en-GB/en-GB.com_example.ini</language>  </languages>    <!-- 媒体文件放置的目录 ,创建并放置到media/com_example目录-->  <media destination="com_example" folder="media">    <filename>index.html</filename>    <folder>images</folder>  </media>    <!-- backend相关的文件及设置 -->  <administration>  <!-- 在后台的component菜单中创建该component的菜单项 -->    <menu img="class:example">COM_EXAMPLE_MENU</menu>    <submenu>  <!-- Note that all & must be escaped to & for the file to be valid XML and be parsed by the installer -->  <menu link="option=com_example" view="links" img="class:example"alt="example/Submenu1">COM_EXAMPLE_SUBMENU_1</menu>  <menu link="option=com_categories&extension=com_example"view="categories" img="class:example-cat" alt="Example/submenu2">COM_EXAMPLE_SUBMENU_2</menu>    </submenu>        <!-- backend安装的文件,放到WebRoot/administrator/components/com_example下 -->    <files folder="admin">      <filename>index.html</filename>      <filename>example.php</filename><!-- 该组件的入口文件 -->      <filename>access.xml</filename><!-- 控制角色权限的文件 -->      <filename>config.xml</filename><!-- 该组件的options项设置 -->      <filename>controller.php</filename>          <folder>controllers</folder>      <folder>models</folder>      <folder>views</folder>      <folder>tables</folder>      <folder>helpers</folder>      <folder>sql</folder>    </files>        <languages folder="admin">      <language tag="en-GB">language/en-GB/en-GB.com_example.ini</language>      <language tag="en-GB">language/en-GB/en-GB.com_example.sys.ini</language>    </languages>  </administration></extension>

(2)script.php文件,类名一定要为com_componentnameInstallerScript,这里是com_exampleInstallerScript

<?php// No direct access to this filedefined('_JEXEC') or die('Restricted access');/** * Script file of EXAMPLE component */class com_exampleInstallerScript{/** * method to install the component * * @return void */function install($parent){// $parent is the class calling this method//$parent->getParent()->setRedirectURL('index.php?option=com_example');}/** * method to uninstall the component * * @return void */function uninstall($parent){// $parent is the class calling this methodecho '<p>' . JText::_('COM_EXAMPLE_UNINSTALL_TEXT') . '</p>';}/** * method to update the component * * @return void */function update($parent){// $parent is the class calling this methodecho '<p>' . JText::sprintf('COM_EXAMPLE_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>';}/** * method to run before an install/update/uninstall method * * @return void */function preflight($type, $parent){// $parent is the class calling this method// $type is the type of change (install, update or discover_install)echo '<p>' . JText::_('COM_EXAMPLE_PREFLIGHT_' . $type . '_TEXT') . '</p>';}/** * method to run after an install/update/uninstall method * * @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_EXAMPLE_POSTFLIGHT_' . $type . '_TEXT') . '</p>';}}


3)下图为目录及文件的组织,文件下载地址:

http://download.csdn.net/detail/fightingbull/5221439



 

辉辉        

(FightingBull Studio)

 

欢迎转载,但请注明出处:http://blog.csdn.net/fightingbull