:::
主內容區域
9-1 編輯區塊主函數
一、修改主函數
- 我們先編輯 blocks\list_signup.php 中的主函數list_signup(),其主要目的就是抓出區快要呈現的內容。
<?php //區塊主函數:列出所報者 function list_signup($options) { global $xoopsDB; if ($_GET['action_id']) { $tbl = $xoopsDB->prefix('signups'); $action_id = intval($_GET['action_id']); $sql = "SELECT * FROM `$tbl` where `action_id` = '{$action_id}'"; $result = $xoopsDB->query($sql) or web_error($sql); $signups = []; while ($val = $xoopsDB->fetchArray($result)) { $signups[] = $val; } return $signups; } } -
我們利用 $_GET['action_id'] 來取得當活動編號。
-
接著到 signups 先撈出所有報名紀錄,做成三維陣列,傳至區塊樣板 templates\blocks\list_signup.tpl。
-
無須特別去 assign(),只要 return 變數即可,在樣板中,自動會轉換為 <{$block}>。
二、修改區塊樣板
- 編輯 templates\blocks\list_signup.tpl
<table class="table table-hover table-striped"> <thead> <tr class="info"> <th>姓名</th> <th>Email</th> </tr> </thead> <tbody> <{foreach from=$block item=signup}> <tr> <td><{$signup.uid}></td> <td><{$signup.signup_date}></td> </tr> <{foreachelse}> <tr> <td colspan=2>暫無人報名</td> </tr> <{/foreach}> </tbody> </table>
9. 新增區塊