會員管理功能算是後台功能中較簡單的,而且大部份的程式碼都和管理權限設置相似,因此這邊建議是接在管理權限設置功能做完後順著做下來把它先完成。
- 複製
./view/backend/admin.php
的內容貼到./view/backend/user.php
中。 - 在類別中建立後台頁面方法
/controller/User.php1
2
3
4function backend(){
$view['rows']=$this->all();
return $this->view("./view/backend/user.php",$view);
} - 在
./view/backend/user.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<h2 class="ct">會員管理</h2>
<table class="all">
<tr class="ct">
<td class="tt">姓名</td>
<td class="tt">會員帳號</td>
<td class="tt">註冊日期</td>
<td class="tt">操作</td>
</tr>
<?php
foreach($rows as $row){
<tr class="ct">
<td class="pp"><?=$row['name'];?></td>
<td class="pp"><?=$row['acc'];?></td>
<td class="pp"><?=$row['regdate'];?></td>
<td class="pp">
<button onclick="location.href='?do=edit_user&id=<?=$row['id'];?>'">修改</button>
<button onclick="del('User',<?=$row['id'];?>)">刪除</button>
</td>
</tr>
<?php
}
?>
</table>
<div class="ct">
<button onclick="location.href='index.php'">返回</button>
</div>
- 建立
./view/backend/edit_user.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
$row=$User->find($_GET['id']);
<h2 class="ct">編輯會員資料</h2>
<form action="./api/edit_user.php" method="post">
<table class="all">
<tr>
<td class="tt ct">帳號</td>
<td class="pp"><?=$row['acc'];?></td>
</tr>
<tr>
<td class="tt ct">密碼</td>
<td class="pp"><?=str_repeat("*",strlen($row['acc']));?></td>
</tr>
<tr>
<td class="tt ct">姓名</td>
<td class="pp"><input type="text" name="name" value="<?=$row['name'];?>"></td>
</tr>
<tr>
<td class="tt ct">電話</td>
<td class="pp"><input type="text" name="tel" value="<?=$row['tel'];?>"></td>
</tr>
<tr>
<td class="tt ct">住址</td>
<td class="pp"><input type="text" name="addr" value="<?=$row['addr'];?>"></td>
</tr>
<tr>
<td class="tt ct">電子信箱</td>
<td class="pp"><input type="text" name="email" value="<?=$row['email'];?>"></td>
</tr>
</table>
<div class="ct">
<input type="hidden" name="id" value="<?=$row['id'];?>">
<input type="submit" value="編輯">
<input type="reset" value="重置">
<input type="button" value="取消" onclick="location.href='?do=user'">
</div>
</form>
- 複製
./api/save_admin.php
,並更名為edit_user.php
,修改相關的資料表名,及最後要導向的位置,即可完會編輯會員資料的功能。1
2
3include_once "../base.php";
$User->save($_POST);
to("../backend.php?do=user");