0%

這邊其實幾乎算送分了,因為主選單的內容己經在版型檔案中先做好了,連背景圖都設定好了,所以這邊唯一需要做的是把動態文字廣告的字打上去即可,這邊要注意的是動態文字廣告區的右側要留點空間給登入資訊使用。

閱讀全文 »

這邊我們先來處理網站標題區,這邊比較麻煩的是瀏灠人次不是採總計,而是分日計算然後再總計;雖然題目沒有指示是否要和第一題一樣的機制,但我們在設計上為了避免瀏灠人次一直跳動,所以還是採用session來紀錄使用者的進站狀況,關閉瀏灠器再開才會重新計算;

閱讀全文 »

整理好素材及開完資料表後,接著我們會製作DB類別檔,把會用到的一些功能都封裝在DB類別中,再透過繼承去延伸各個需要的功能

建立各資料表的繼承類別

DB類別請參考先前關於DB class的解釋:
[技能檢定]網頁乙級檢定-前置作業-程式功能整合測試

在 Controller 目錄下建立以下檔案,原則上是一張資料表對應一個檔案,其中 DB.php 是父類別:

接著在每個類別檔中引入DB.php,並且建立繼承的類別:

Controller/Viewer.php

1
2
3
4
5
6
7
8
include_once "DB.php";

class Viewer extends DB{
function __construct()
{
parent::__construct('viewer');
}
}

Controller/User.php

1
2
3
4
5
6
7
8
include_once "DB.php";

class User extends DB{
function __construct()
{
parent::__construct('users');
}
}

Controller/News.php

1
2
3
4
5
6
7
8
include_once "DB.php";

class News extends DB{
function __construct()
{
parent::__construct('news');
}
}

Controller/Que.php

1
2
3
4
5
6
7
8
include_once "DB.php";

class Que extends DB{
function __construct()
{
parent::__construct('que');
}
}

Controller/Log.php

1
2
3
4
5
6
7
8
include_once "DB.php";

class Log extends DB{
function __construct()
{
parent::__construct('log');
}
}

建完各個類別後,為了後續的操作方便,我們將這些類別都引入到一個檔案中,而這個檔案又會分別被 index.phpbackend.php 引入,相當於整個網站的所有頁面都可以引用到這個檔案的內容。

/base.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
session_start();       //啟用session功能
date_default_timezone_set("Asia/Taipei"); //設定網站的時區為亞洲台北

//將各個類別引入到這個共用檔中
include_once __DIR__ . "/Controller/Viewer.php";
include_once __DIR__ . "/Controller/User.php";
include_once __DIR__ . "/Controller/News.php";
include_once __DIR__ . "/Controller/Que.php";
include_once __DIR__ . "/Controller/Log.php";

//簡易的自訂函式
/**
* 用來顯示陣列內容-除錯時使用
*/
function dd($array){
echo "<pre>";
print_r($array);
echo "</pre>";
}

/**
* 簡化header('location:')的使用
* 將請求導向其他檔案或頁面
*/
function to($url){
header("location:".$url);
}

/**
* 用來處理較複雜的sql語句,比如子查詢或聯表查詢
* 預設回傳的資料是2維陣列
*/
function q($sql){
$pdo=new PDO("mysql:host=localhost;charset=utf8;dbname=db13",'root','');
return $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}

//宣告各個類別的物件變數
$Viewer=new Viewer;
$User=new User;
$News=new News;
$Que=new Que;
$Log=new Log;

接著將這個檔案引入到 index.phpbackend.php 中:

/index.php/backend.php

1
2
3
4
<?php include_once "base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0039) -->
<html xmlns="http://www.w3.org/1999/xhtml">

根據版型的提示,前台有一個登理登入的按鈕可以連到登入畫面,登入後到後台時有一個按鈕可以登出,而如果在登入的狀態下停在前台時,原本的管理登入按鈕會變成是可以跳到後台的按鈕,這表示我們需要有一個機制來記錄管理員的登入狀態,才能根據這個狀態對按鈕做出不同的功能,而後台的管理登出按鈕,題目只要求可以跳到管理登入的畫面,並沒有要求要做出真正的登出功能,比如清除session來登出,因此如果時間來不及,可以做成連結跳轉到登入畫面就可以了。時間足夠的話,可以把清除session的真正登出功能也做上。

閱讀全文 »