商城实战之后台栏目管理
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
defined('ACC')||exit('ACC Denied');
class Model {
protected $table = NULL; // 是model所控制的表
protected $db = NULL; // 是引入的mysql对象
public function __construct() {
$this->db = mysql::getIns();
}
public function table($table) {
$this->table = $table;
}
}
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
class CateModel extends Model {
protected $table = 'cate';
public function add($data) {
return $this->db->autoExecute($this->table,$data,'insert');
}
}
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
class TestModel extends Model {
protected $table = 'test';
public function reg($data) {
return $this->db->autoExecute($this->table,$data,'insert');
}
// 取所有的数据
public function select() {
return $this->db->getAll('select * from ' . $this->table);
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
</script>
<style type="text/css">
tr{
background:blue;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td>列1</td><td>列2</td>
</tr>
<?php foreach($list as $v) { ?>
<tr>
<td><?php echo $v['t1'];?></td>
<td><?php echo $v['t2'];?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
/***
所有由用户直接访问到的这些页面
都得先加载init.php
***/
require('./include/init.php');
/*
我们的目的:
测试框架能否正常运行
能否正常过滤非法字符
能否正常操作数据库
*/
$mysql = mysql::getIns();
$test = new TestModel();
var_dump($test->reg(array('t1'=>'adminuser','t2'=>'adminuser')));
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
define('ACC',true);
require('./include/init.php');
/***
以往的做法是
接收数据
检验数据
拼凑sql,并执行
判断返回值
现在的MVC开发方式
接收数据
检验数据
把数据交给model去写入数据库
判断model的返回值
***/
// 接收
$data['catename'] = $_POST['catename'];
$data['intro'] = $_POST['intro'];
// 关于名称的检测,如有无重复. 此处不演示
// 调用model,来执行
$cateModel = new CateModel();
if($cateModel->add($data)){
$res = true;
} else {
$res = false;
}
// 把结果展示到view里.
// 此处也直接打印
echo $res?'成功':'失败';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
</script>
<style type="text/css">
</style>
</head>
<body>
<form action="cateadd.php" method="post">
栏目名称:<input type="text" name="catename" /><br />
栏目简介:<input type="text" name="intro" /><br />
<input type="submit" value="提交" />
</form>
</body>
</html>
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
/***
所有由用户直接访问到的这些页面
都得先加载init.php
***/
define('ACC',true);
require('./include/init.php');
/*
我们的目的:
测试框架能否正常运行
能否正常过滤非法字符
能否正常操作数据库
*/
$test = new TestModel();
var_dump($test->reg(array('t1'=>'frontuser','t2'=>'frontuser')));
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
/***
所有由用户直接访问到的这些页面
都得先加载init.php
***/
require('./include/init.php');
/*
我们的目的:
测试框架能否正常运行
能否正常过滤非法字符
能否正常操作数据库
*/
$mysql = mysql::getIns();
$t1 = $_GET['t1'];
$t2 = $_GET['t2'];
/*
$sql = "insert into test(t1,t2) values('$t1','$t2')";
var_dump($mysql->query($sql));
*/
var_dump($mysql->autoExecute('test',$_GET,'insert'));
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>新建网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript">
</script>
<style type="text/css">
tr{
background:blue;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td>列1</td><td>列2</td>
</tr>
<?php
$mysql = mysql::getIns();
$list = $mysql->getAll('select * from test');
?>
<?php foreach($list as $v) { ?>
<tr>
<td><?php echo $v['t1'];?></td>
<td><?php echo $v['t2'];?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
<?php
/****
燕十八 公益PHP讲堂
论 坛: http://www.zixue.it
微 博: http://weibo.com/Yshiba
YY频道: 88354001
****/
require('./include/init.php');
/*
我们的目的:
测试框架能否正常运行
能否正常过滤非法字符
能否正常操作数据库
*/
$test = new TestModel();
$list = $test->select();
///print_r($list);
include(ROOT . 'view/userlist.html');
浙公网安备 33010602011771号