AppleStar

  • Increase font size
  • Default font size
  • Decrease font size
首页 Developer Joomla Joomla扩展模块开发文档(module)

Joomla扩展模块开发文档(module)

E-mail 打印 PDF

概述

************************************************************************

扩展模块用于简单的页面展示,可以应用于多个不同的组件

扩展模块可以使页面构建更加灵活并且可以提高程序的重用性

模块分为前台和后台两种

在配置文件的install元素中设置属性client="administrator"即为后台模块

前台的模块的目录为<root>/modules,后台模块的目录为<root>/administrator/modules

扩展组件目录的命名约定是mod_<Name>

文件

************************************************************************

一个基本的模块包括四个文件

mod_helloworld.php - 入口文件,执行相关初始化操作,通过helper.php获取数据并设置模板

mod_helloworld.xml - 配置文件,设置模块安装相关参数

helper.php - 一般是模块的一个helper类,进行实际的数据读取,逻辑运算的相关操作

tmpl/default.php - 模板文件,设置模块的显示效果

mod_helloworld.php

示例:

<?php
/**
 * Hello World! Module Entry Point
 * 
 * @package    Joomla.Tutorials
 * @subpackage Modules
 */
 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
 
// 引入helper
require_once( dirname(__FILE__).DS.'helper.php' );

// 获取数据
$hello = modHelloWorldHelper::getHello( $params );
// 加载模板
require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) );

helper.php

示例:

<?php
/**
 * Helper class for Hello World! module
 * 
 * @package    Joomla.Tutorials
 * @subpackage Modules
 */
class modHelloWorldHelper                // helper类的命名mod<name>Helper(非强制性的命名约定)
{
    /**
     * Retrieves the hello message
     *
     * @param array $params              // 一个填充了模块参数的JParameter对象
     * @access public
     */    
    function getHello( $params )
    {
    	$hello = $params->get( 'hello' );// 获取hello参数的值
        return $hello;
    }
}

tmpl/default.php

示例:

<?php // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<?php echo $hello; ?>

模板中可以直接使用入口文件中定义的变量

mod_helloworld.xml

示例:

<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<!-- 扩展类型:type=[component|module|plugin] version=<joomla版本> [client="administrator"] 后台模块 [method="upgrade"] 以更新方式安装-->
    <name>Hello, World!</name>
    <version>1.5.0</version><!-- 扩展的版本信息 -->
    <description>A simple Hello, World! module.</description>
    <!-- 文件列表 -->
    <files>
        <filename>mod_helloworld.xml</filename>
        <filename module="mod_helloworld">mod_helloworld.php</filename>
        <filename>index.html</filename>
        <filename>helper.php</filename>
        <filename>tmpl/default.php</filename>
        <filename>tmpl/index.html</filename>
    </files>
    <!--设置模块参数-->
    <params>
		<param name="hello" type="text" default="hello,world!" label="hello" description="hello string" />
    </params>
</install>

参数的相关设置可以应用于所有类型的扩展

最后更新于: 2010-02-10 06:24  

添加评论


验证码
刷新

用户登录

ADS