Xoops 區塊-在 xoops_version.php 中設定 xoops 區塊

日期 2010年09月06日 22:32:10 | 新聞類別: 模組開發

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


 

Step 1 – xoops_version.php 中設定xoops 區塊

用編輯器打開tutorial/xoops_version.php。在?> 前新增以下的程式碼。

// Blocks

$modversion['blocks'][1]['file'] = "tutorial_block.php";

$modversion['blocks'][1]['name'] = 'Block for Tutorial';

$modversion['blocks'][1]['description'] = 'This is a Block for the tutorial module';

$modversion['blocks'][1]['show_func'] = "tut_blockList";

$modversion['blocks'][1]['template'] = 'tutorial_block.html';

$modversion['blocks'][1]['file'] = "tutorial_block.php";這行是告訴xoops 控制這個區塊的php 函式是在哪個檔案內。每個檔案內可以有多個函式。除非程式碼太多行,否則通常我會把我所有的函式放在同一個檔案內。程式太多行的話我會使用多個檔案放這些程式碼。

$modversion['blocks'][1]['name'] = 'Block for Tutorial';這行是設定區塊的名稱。依據Xoops 程式標準你應該使用語言常數而不是實際名稱。在這個範例中只是為了讓你容易了解才這麼作。

$modversion['blocks'][1]['description'] = 'This is a Block for the tutorial module';這行是區塊的描述。會在區塊管理頁面中顯示。

$modversion['blocks'][1]['show_func'] = "tut_blockList";這行是實際控制區塊行為的函式名稱。根據經驗我會在函式名稱前面加上模組名稱的縮寫以便於與其它模組程式作區隔。

$modversion['blocks'][1]['template'] = 'tutorial_block.html';這行是設定函式使用的smarty 樣板。


小提示
當您在xoops_version.php 內建立樣版與區塊時,編號必須是:

// Templates

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

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

$modversion['templates'][2]['file'] = 'tut_client_list.html';

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

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

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

現在假設你需要在編號2與編號3中間新增一個樣板時該怎麼作呢?在樣版很少時改變編號可能相當的容易,但是假設是在大模組裡面;如有40個或是更多的樣板時改變編號會變得相當的不方便。要怎麼解決這個問題呢?其實是相當簡單的,只要用一個變數就可以解決了:

// Templates

$i=1;

$modversion['templates'][$i]['file'] = 'tut_form.html';

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

$i++;

$modversion['templates'][$i]['file'] = 'tut_client_list.html';

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

$i++;

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

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

$i++;

這麼一來我就可以很容易的在樣版之間新增樣板。我讓$i 處理編號,初始值是1($i=1;),每個樣板後加1($i++;)。





本篇新聞來自:XOOPS Site
https://www.xoops.org.tw

本篇新聞的連結網址是:
https://www.xoops.org.tw/modules/news/article.php?storyid=59