0%

[技能檢定]題組四 步驟5 製作後台頁尾版權區

本題組有些項目的配分明顯的CP值不同,比如頁尾版權區合計有四項描述共二十分,但實際完成這個功能的前後台,可能不用到五分鐘,所以我們會優先把這些項目做完,爭取時間來處理其它的項目

  1. 分別先在 index.phpback.php 的最前頭加上 <?php include_once "./api/db.php";?> 這樣可以方便之後的引入檔來使用
    index.php / back.php
    1
    2
    3
    4
    <?php include_once "./api/db.php";?>
    <!DOCTYPE html>
    <!-- saved from url=(0039) -->
    <html xmlns="http://www.w3.org/1999/xhtml">
  2. 先在 bottom 資料表中增加一筆頁尾版權資料。

  1. 先在 index.phpback.php 的最後頁尾版權區加上取出版權文字的語法。
    1
    2
    3
    4
    5
    <div id="bottom" 
    style="line-height:70px;background:url(icon/bot.png); color:#FFF;"
    class="ct">
    <?=$Bottom->find(1)['bottom'];?>
    </div>
  2. 接著在 ./back/ 目錄中的 bot.php 檔,建置後台需要的表單及功能
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <h2 class="ct">編輯頁尾版權區</h2>
    <!--表單資料送到本頁-->
    <form action="?do=bot" method="post">
    <!-- table.all>tr>td.tt+td.pp>input:text -->
    <table class="all">
    <tr>
    <td class="tt">頁尾宣告內容</td>
    <td class="pp">
    <input type="text" name="bottom" value="<?=$Bottom->find(1)['bottom'];?>">
    </td>
    </tr>
    </table>
    <div class="ct">
    <input type="submit" value="編輯">
    <input type="reset" value="重置">
    </div>
    </form>

  1. 這邊我們不另外寫一個API檔來處理更新資料,而是在form表單的action中指定傳送表單到 ?do=bot 也就是當前的頁面直接處理,這樣會比較省時間
  2. 我們直接在 back/bot.php 中判斷是否有版權宣告的表單送出的動作,同時更新頁尾版權的內容
    ./back/bot.php
    1
    2
    3
    if(!empty($_POST)){
    $Bottom->save(['bottom'=>$_POST['bottom'],'id'=>1]);
    }