- 在
./view/backend/
目錄中建立add_admin.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<h2 class="ct">新增管理帳號</h2>
<form action="./api/save_admin.php" method="post">
<table class="all">
<tr>
<td class="tt ct">帳號</td>
<td class="pp"><input type="text" name="acc" id="acc"></td>
</tr>
<tr>
<td class="tt ct">密碼</td>
<td class="pp"><input type="password" name="pw" id="pw"></td>
</tr>
<tr>
<td class="tt ct">權限</td>
<td class="pp">
<div>
<input type="checkbox" name="pr[]" value="1">
商品分類與管理
</div>
<div>
<input type="checkbox" name="pr[]" value="2">
訂單管理
</div>
<div>
<input type="checkbox" name="pr[]" value="3">
會員管理
</div>
<div>
<input type="checkbox" name="pr[]" value="4">
頁尾版權區管理
</div>
<div>
<input type="checkbox" name="pr[]" value="5">
最新消息管理
</div>
</td>
</tr>
</table>
<div class="ct">
<input type="submit" value="新增">
<input type="reset" value="重置">
</div>
</form>
- 在
./api/
目錄中建立save_admin.php
檔案,並撰寫新增/更新管理帳號的程式碼1
2
3
4
5
6
7include_once "../base.php";
//使用序列化的方式將權限陣列轉成字串
$_POST['pr']=serialize($_POST['pr']);
$Admin->save($_POST);
to("../backend.php"); - 複製一份
./view/backend/add_admin.php
並改名為edit_admin.php
,然後根據$_GET['id']
的值來取出資料 - 要記得在
edit_admin.php
中增加一個隱藏欄位把資料的 id 值帶入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
44
45
46$row=$Admin->find($_GET['id']);
$row['pr']=unserialize($row['pr']);
<h2 class="ct">修改管理員權限</h2>
<form action="./api/save_admin.php" method="post">
<table class="all">
<tr>
<td class="tt ct">帳號</td>
<td class="pp"><input type="text" name="acc" value="<?=$row['acc'];?>"></td>
</tr>
<tr>
<td class="tt ct">密碼</td>
<td class="pp"><input type="password" name="pw" value="<?=$row['pw'];?>"></td>
</tr>
<tr>
<td class="tt ct">權限</td>
<td class="pp">
<div>
<input type="checkbox" name="pr[]" value="1" <?=(in_array(1,$row['pr']))?'checked':'';?>>
商品分類與管理
</div>
<div>
<input type="checkbox" name="pr[]" value="2" <?=(in_array(2,$row['pr']))?'checked':'';?>>
訂單管理
</div>
<div>
<input type="checkbox" name="pr[]" value="3" <?=(in_array(3,$row['pr']))?'checked':'';?>>
會員管理
</div>
<div>
<input type="checkbox" name="pr[]" value="4" <?=(in_array(4,$row['pr']))?'checked':'';?>>
頁尾版權區管理
</div>
<div>
<input type="checkbox" name="pr[]" value="5" <?=(in_array(5,$row['pr']))?'checked':'';?>>
最新消息管理
</div>
</td>
</tr>
</table>
<div class="ct">
<input type="hidden" name="id" value="<?=$row['id'];?>">
<input type="submit" value="修改">
<input type="reset" value="重置">
</div>
</form>