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

本文是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 file
defined('_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 method
		echo '<p>' . JText::_('COM_EXAMPLE_UNINSTALL_TEXT') . '</p>';
	}

	/**
	 * method to update the component
	 *
	 * @return void
	 */
	function update($parent)
	{
		// $parent is the class calling this method
		echo '<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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值