首页 > Web开发 > 详细

时间:2014年3月30日14:22:30Model MVC概念

时间:2014-03-31 04:48:35      阅读:610      评论:0      收藏:0      [点我收藏+]


前台用户注册页面 user.php

接受并处理注册 usereg.php  $_POST[]   $sql  $mysql_query()

增删改查都集中到Model中,业务模型,所有的sql语句都在model

<?php

class Model{

protected $table = null;//model所控制的表

protected $db= null;//引入的mysql对象

protected $pk = ‘‘;

public function __Construct(){

$this->db = mysql::getIns();

}

public function table($table){

$this->table = $table;

}

public function add($data){

return $this->db->autoExcute($this->table,$data);

}

public function delete($id){

$sql = "delete from ".$this->table." where ".$this->pk." = ".$id;

if ($this->db->query($sql)) {

return $this->db->affected_rows();

}else{

return false;

}

}

//

public function update($data,$id){

$rs = $this->autoExcute($this->table,$data,‘update‘,‘where ‘.$this->pk.‘ = ‘.$id);

if ($rs) {

return $this->db->affected_rows();

}else{

return false;

}

}

public function select(){

$sql = ‘select * from ‘.$this->table;

return $this->db->getAll($sql);

}

public function find($id){

$sql = "select * from ".$this->table." where ".$this->pk." = ".$id;

return $this->db->getRow($sql);

}

}

?>

testModel.php

class TestModel extends Model{  

protected $table = "test";

public function reg($data){

return $this->db->autoExcute($this->table,$data,‘insert‘);

}

public function select(){

return $this->db->getALL(‘select * from ‘.$this->table);

}

}

数据库  model   view   userlist.php

userlist.php 的最终任务,是把数据显示出来,注意是数据显示

从哪获取的数据,不知道,是从model中传输过来的

userlist.php 显示成什么样子,不知道,由view负责显示

userlist.php 调用model要数据

userlist.php model拿到数据,但并不是直接显示出来,

userlist.php 把数据经过view渲染,得到最终要输出的结果

userlist.php 不能直接操作数据库,要通过model

userlist.php 不能直接输出,要经过view来输出

userlist.php 的作用:响应用户请求,并调度modelview

userlist.php 是用户直接访问的功能页面,称为控制器

控制器 controller 负责响应用户,负责检测数据合法性,调用modelview 不负责sql和样式

模型 Model操作数据库,不针对数据的合法,如$_GET的验证

视图 view 一般没有逻辑,只负责输出


本文出自 “杜国栋个人PHP学习博文” 博客,请务必保留此出处http://duguodong.blog.51cto.com/7667978/1387196

时间:2014年3月30日14:22:30Model MVC概念,布布扣,bubuko.com

时间:2014年3月30日14:22:30Model MVC概念

原文:http://duguodong.blog.51cto.com/7667978/1387196

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!