Skip to content

Commit ced4781

Browse files
committed
增加分类列表
1 parent 8d5430f commit ced4781

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1460
-4
lines changed

sess_test.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
require './session_overwrite.php';
4+
session_start();
5+
var_dump($_SESSION);

session_overwrite.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* 在session开启时执行
4+
* @return [type] [description]
5+
*/
6+
function sess_open(){
7+
echo 'open<br>';
8+
9+
$link = mysql_connect('127.0.0.1:3306','root','root');
10+
mysql_query('set names `utf8`');
11+
mysql_query('use `demo_shop`');
12+
}
13+
/**
14+
* session_start()时,开启seesions被执行
15+
*负责从session纪录中华,将seesion数据读取出来
16+
* @param [type] $sess_id 当前的seession_id
17+
* @return [type] 读取到seesion的数据
18+
*/
19+
function sess_read($sess_id){
20+
echo 'read<br>';
21+
$sql = "select sess_data from `demo_session` where sess_id='$sess_id'";
22+
$result = mysql_query($sql);
23+
if ($row = mysql_fetch_assoc($result)) {
24+
return $row['sees_data'];
25+
}else{
26+
return '';
27+
}
28+
29+
}
30+
31+
/**
32+
* 在脚本结束时被执行
33+
*
34+
* 负责,将当前的session 数据同步到当前的seesion纪录中
35+
* @param [type] $sees_id [description]
36+
* @param [type] $sees_data [description]
37+
* @return [type] [description]
38+
*/
39+
function sess_write($sees_id,$sees_data){
40+
echo 'write<br>';
41+
$sql = "insert into `demo_session` values('$sees_id','$sess_data') on dupllicate key update sess_data='$sess_data";
42+
return mysql_query($sql);
43+
}
44+
45+
/**
46+
* 在调用了seesion_destory()系统函数,被自动调用
47+
* 负责的功能 利用当前的ID 删除被当前的session 的纪录
48+
* @return [type] [description]
49+
*/
50+
function sess_destory(){
51+
echo 'destory<br>';
52+
$sql = "delete from `session` where seess_id='$sess_id";
53+
return mysql_query($sql);
54+
}
55+
56+
function sess_gc(){
57+
echo 'gc<br>';
58+
}
59+
60+
function sess_close(){
61+
echo 'close<br>';
62+
return true;
63+
64+
}
65+
session_set_save_handler(
66+
'sess_open',
67+
'sess_close',
68+
'sess_read',
69+
'sess_write',
70+
'sess_destory',
71+
'sess_gc'
72+
);

shop/app/controller/back/AdminController.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ public function signinAction(){
1414
//利用用户名 和 密码 验证用户身份
1515
$model_admin = new AdminModel;
1616
if ($model_admin->checkByLogin($_POST['username'],$_POST['password'])) {
17-
setcookie('is_login','yes');
17+
//setcookie('is_login','yes');
18+
session_start();
19+
$_SESSION['is_login'] = 'yes';
1820
//echo '合法用户';
1921
$this->jump('index.php?p=back&c=Index&a=index');
2022
}else{
23+
//非法用户
2124
//echo '非法用户';
2225
$this->jump('index.php?p=back&c=Admin&a=index','非法用户',2);
2326
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class CategoryController extends Controller{
3+
/**
4+
*分类列表展示
5+
* @return [type] [description]
6+
*/
7+
public function listAction(){
8+
$model_name = new CategoryModel;
9+
$list = $model_name->getList();
10+
require CURR_VIEW_DIR.'category.html';
11+
}
12+
}

shop/app/controller/back/IndexController.class.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
class IndexController extends Controller{
44

55
public function indexAction(){
6-
if (isset($_COOKIE['is_login']) && $_COOKIE['is_login'] == 'yes') {
6+
//判断用户是否已经登陆
7+
//if (isset($_COOKIE['is_login']) && $_COOKIE['is_login'] == 'yes') {
8+
session_start();
9+
if(isset($_SESSION['is_login']) && $_SESSION['is_login'] == 'yes'){
710
# code...
811
}else{
9-
die('没有登录');
12+
//die('没有登录');
13+
$this->jump('index.php?p=back&c=Admin&a=index','没有用户',5);
14+
die();
1015
}
1116
require CURR_VIEW_DIR.'index.html';
1217
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
class CategoryModel extends Model{
3+
/**
4+
* 获取所有分类信息
5+
* @return 所有分类
6+
*/
7+
public function getList(){
8+
$sql = "select * from `demo_category` order by sort_order";
9+
$list = $this->db->fetchAll($sql);
10+
//return $list;
11+
$list = $this->getTree($list,0,0);
12+
return $list;
13+
}
14+
15+
/**
16+
* 获取树形视图
17+
* @param [type] $arr 所有信息
18+
* @param integer $pid 父分类ID
19+
* @param [type] $deep 当前的分类深度
20+
* @return [type] [description]
21+
*/
22+
public function getTree($arr,$pid=0,$deep){
23+
static $tree = array();
24+
foreach ($arr as $row ) {
25+
if ($row['parent_id'] == $pid) {
26+
$row['deep'] =$deep;
27+
$tree[ ]= $row;
28+
$this->getTree($arr,$row['cat_id'],$deep+1);
29+
}
30+
}
31+
return $tree;
32+
}
33+
}

shop/app/view/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)