帳號登錄
帳號:
密碼:
記住我 | 忘記密碼 | 帳號註冊
網站導覽
模組開發 : 開始建立模組
作者 elie 於 2010年08月19日 21:12:41 (5013 次閱讀)

原始出處 http://www.xoops.org/modules/mediawiki/index.php/Dev:start_to_make_a_module

 

Aspects

兩個寫XOOPS 模組很重要且需要知道的物件:$xoopsUserXoopsDB

Anatomy of a Module Page

凡是經由瀏覽器瀏覽的模組檔案(不包含總是由其他檔案引入的檔案)都應該放在modules/modulename 目錄下。

模組程式要作的第一件事情是引入模組根目錄下的"mainfile.php"。Mainfile.php 引入的include/common.php 將會:

   設定資料庫的連線

   如果有帳號密碼則登入使用者

   引入XOOPS API 函式

   取得現在模組($xoopsModule)

   取得模組設定選項($xoopsModuleConfig)

   引入相關語言檔

   檢查網站是否關閉 – 如果沒有的話則使用者可以使用

   檢查使用者是否有權限使用現在的模組

在引入mainfile.php 後,程式會決定使用到的樣版– 也就是使用Smarty 樣版的網頁– 經由

   $xoopsOption['template_main'] = "template_name.ext";

下一步是引入根目錄的header.php,也就是會:

   產生Smarty 物件,$xoopsTpl(注意:從2.2版開始這個動作由 include/common.php 完成)

   檢查網頁快取設定並決定使用快取畫面或建立區塊

注意:如果在引入header.php 前沒有決定$xoopsOption['template_main'] 設定的話將不會使用網頁快取。

現在XOOPS 主要的部分都已經被引入了,檔案已經可以開始處理呈現在網頁上的資料與指定變數給Smarty。這些檔案可以是任何的PHP 檔案,雖然這些檔案不一定要使用XOOPS 核心函式。

如果檔案沒有任何模組內以外的內容(像是標頭檔、廣告,與區塊等– 使用的情況可能是跳出視窗),這個時候$xoopsOption['output_type'] 可以設為"plain" – 這種情況下引入header.php 純粹是確定網頁快取。

檔案最後要引入根目錄的footer.php,將會展示theme 目錄的theme.html 與稍早取得的區塊與模組內容。

注意:在使用Smarty 的網頁沒有引入footer.php 的話會造成沒有內容與沒有錯誤訊息的空白頁。如果網頁沒有使用Smarty,只會產生網頁的內容而沒有區塊、標頭檔、頁尾,與網頁風格主題的畫面。

Anatomy of a module Administration page

管理者畫面都會在modules/modulename/admin 目錄下且結構如下:

include ('../../../include/cp_header.php');

xoops_cp_header();

//Module admin code similar to a frontside module page (Note: Before XOOPS 2.2, $xoopsTpl could not be used directly in the administration area, but would have to be manually instantiated or HTML output directly in the PHP files)

xoops_cp_footer();


可列印模式 轉寄給朋友

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.