11-2
列出單一活動
一、製作函數
- 讀出單一活動的流程已經有了,所以,直接完成函數show_action($action_id)
//列出指定活動
function show_action($action_id)
{
global $db, $smarty;
$sql = "SELECT * FROM `actions` where `action_id` ='{$action_id}'";
$result = $db->query($sql);
if (!$result) {
throw new Exception($db->error);
}
$action = $result->fetch_assoc();
$smarty->assign('action', $action);
}
二、修改主樣板
- 編輯 templates\index.tpl
{if $op=="regist"}
{include file='regist_form.tpl'}
{elseif $op=="list_action"}
{include file='list_action.tpl'}
{elseif $op=='show_action'}
{include file='show_action.tpl'}
{else}
{$content}
{/if}
三、新增專屬樣板
- 新增 templates\show_action.tpl
<h2>{$action.title}</h2>
<div class="panel panel-default">
<div class="panel-heading">活動日期:{$action.action_date}</div>
<div class="panel-body">
{$action.content}
</div>
<div class="panel-footer">報名截止日:{$action.end_date}</div>
</div>