帳號登錄
帳號:
密碼:
記住我 | 忘記密碼 | 帳號註冊
網站導覽
模組開發 : 在模組中使用 Smarty 樣版-開始
作者 elie 於 2010年09月03日 20:44:44 (4999 次閱讀)

原始出處 http://www.xoops.org/modules/mediawiki/index.php?title=Using_Smarty_templates_in_a_module

 

開始

本教材將告訴你如何使用smarty 樣版與在XOOPS 模組中如何消毒。我們開始吧!

首先由此part1 取得tutorial 模組並安裝。

在index.php 中我們可以看到php 與html 程式碼參雜在一起。在大型模組中很難找到<td> 是對應到哪一個。smarty 最大的優點就是能夠解決這個問題。我們可以建立易於讀取且可動態改變的HTML 樣版。XOOPS 有內建使用smarty 的程式碼。

我們先來建立第一個XOOPS 的smarty 樣版。打開xoops_version.php 後寫入下面紅色的程式碼:

<?php

// Tutorial Module

// Created by kaotik

 

$modversion['name'] = "Tutorial";

$modversion['version'] = 2.00;

$modversion['description'] = "This is a tutorial module to teach how to build a simple module";

$modversion['author'] = "KaotiK";

$modversion['credits'] = "KaotiK";

$modversion['help'] = "";

$modversion['license'] = "GPL see LICENSE";

$modversion['official'] = 0;

$modversion['image'] = "images/tutorial.png";

$modversion['dirname'] = "tutorial";

 

// Admin

$modversion['hasAdmin'] = 0;

 

// Menu

$modversion['hasMain'] = 1;

 

$modversion['sqlfile']['mysql'] = "sql/mysql.sql";

$modversion['tables'][0] = "tutorial_myform";

 

// Templates

$modversion['templates'][1]['file'] = 'tut_main.html';

$modversion['templates'][1]['description'] = '';

 

?>

這兩段程式碼是告訴XOOPS 在資料庫內新增一個叫作tut_main.html 的樣版。現在在tutorial 模組內新增一個templates 的目錄,在這個目錄下新增一個tut_main.html。(注意:一般而言XOOPS 所使用的樣版檔案副檔名都是.html。這個檔案應該是空白的。)現在到網站的模組管理頁面並更新tutorial 模組。你會看到XOOPS 有處理tut_main.html 了,很好,我們可以進入下個步驟了。


可列印模式 轉寄給朋友

The XOOPS organisation ("XOOPS") is committed to protecting the privacy of users of the XOOPS.org sites.
The website used Ver.2.4.5 POWERED BY XOOPS PROJECT.