
- Joomla 基礎教程
- Joomla - 首頁
- Joomla - 概述
- Joomla - 安裝
- Joomla - 架構
- Joomla - 控制面板
- Joomla - 工具欄
- Joomla - 選單選單
- Joomla - 內容選單
- Joomla - 元件選單
- Joomla - 擴充套件選單
- Joomla - 幫助選單
- Joomla 模組
- Joomla - 建立模組
- Joomla - 麵包屑模組
- Joomla - 資訊聚合顯示模組
- Joomla - 頁尾模組
- Joomla - 最新新聞模組
- Joomla - 搜尋模組
- Joomla - 隨機圖片模組
- Joomla - 線上使用者模組
- Joomla - 資訊釋出模組
- Joomla - 捐贈模組
- Joomla 全域性設定
- Joomla - 系統設定
- Joomla - 媒體設定
- Joomla - 語言管理器
- Joomla - 私人訊息
- Joomla - 群發郵件
- Joomla - 快取管理
- Joomla - 使用者設定
- Joomla - 除錯
- Joomla 高階
- Joomla - 模板管理器
- Joomla - 自定義模板
- Joomla - 新增模板
- Joomla - 建立模板
- Joomla - 自定義 Logo
- Joomla - 分類管理
- Joomla - 新增內容
- Joomla - 內容格式化
- Joomla - 文章元資料
- Joomla - 新增橫幅廣告
- Joomla - 新增聯絡方式
- Joomla - 新增新聞源
- Joomla - 新增論壇
- Joomla - 新增網頁連結
- Joomla - 外掛管理器
- Joomla - 擴充套件管理器
- Joomla - 網站備份
- Joomla - 網站 SEO
- Joomla 有用資源
- Joomla - 常見問題解答
- Joomla - 快速指南
- Joomla - 有用資源
- Joomla - 討論
Joomla - 建立模組
在本章中,我們將學習在 Joomla 中**建立模組**。模組是靈活且輕量級的擴充套件,可用於頁面渲染。
建立模組
以下是建立 Joomla 模組的簡單步驟。
**步驟 1** - 在您的 **Joomla** → **modules** 資料夾中建立一個名為 **mod_firstmodule** 的資料夾。

**步驟 2** - 在 **mod_firstmodule** 資料夾中建立一個名為 "helper.php" 的檔案。此檔案包含名為 helper 的類名,它有助於在模組輸出中顯示檢索到的資料。
helper.php
<?php /** * Helper class for Hello World! module * * @package Joomla.Tutorials * @subpackage Modules * @link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module * @license GNU/GPL, see LICENSE.php * mod_helloworld is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. */ class ModHelloWorldHelper { /** * Retrieves the hello message * * @param array $params An object containing the module parameters * * @access public */ public static function getHello($params) { return 'Hello, World!'; } } ?>
**步驟 3** - 建立一個名為 **mod_helloworld.php** 的檔案。它是模組的入口點,執行初始化例程,收集必要的資料並使用模板顯示模組輸出。
mod_helloworld.php
<?php /** * Hello World! Module Entry Point * * @package Joomla.Tutorials * @subpackage Modules * @license GNU/GPL, see LICENSE.php * @link http://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module * mod_helloworld is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. */ // No direct access defined('_JEXEC') or die; // Include the syndicate functions only once require_once dirname(__FILE__) . '/helper.php'; $hello = modHelloWorldHelper::getHello($params); require JModuleHelper::getLayoutPath('mod_helloworld'); ?>
**步驟 4** - 建立一個 **mod_helloworld.xml 檔案**。此檔案包含有關模組的資訊。此 xml 檔案包含要為模組安裝到 Joomla 中的檔案的資訊。
mod_helloworld.xml 檔案
<?xml version = "1.0" encoding = "utf-8"?> <extension type = "module" version = "3.1.0" client = "site" method="upgrade"> <name>Hello, World!</name> <author>Tutorials Point</author> <version>1.0.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> <config> </config> </extension>
**步驟 5** - 建立一個名為 **index.html** 的簡單 html 檔案。編寫此檔案的目的是,不允許瀏覽建立的目錄。當用戶瀏覽到這些目錄時,將顯示 index.html 檔案。您甚至可以將此檔案保留為空。
index.html
<html> <body> Welcome to Tutorials Point!!!!! </body> </html>
**步驟 6** - 建立一個名為 **tmpl** 的資料夾。將 **default.php** 檔案(如下所示)和 index.html(在步驟 (5) 中建立)放置在 **tmpl** 資料夾下。default.php 檔案是一個顯示模組輸出的模板。
default.php
<?php /** * @package Joomla.Site * @subpackage mod_firstmodule * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; > <p>Hello World!!!!!!</p>
完成所有這些檔案的建立後,壓縮整個 **mod_firstmodule** 資料夾。
**步驟 7** - 轉到 Joomla 管理員中的 **擴充套件** → **擴充套件管理器**,您將看到以下螢幕。在這裡,您可以上傳和安裝您建立的模組檔案,即 **mod_firstmodule** 資料夾。單擊 **選擇檔案** 並選擇建立的模組檔案(壓縮檔案)。單擊 **上傳並安裝** 按鈕以上傳模組檔案。

**步驟 8** - 上傳和安裝後,轉到 **模組管理器** 並單擊 **新建**。在那裡,您可以檢視您建立的模組檔案,如下所示。

**步驟 9** - 您可以像分配其他模組一樣分配此模組,然後釋出它。