#1 yaoxh
speed在 遇到复杂的sql,我们得使用findsql或runsql来实现数据操作,这些操作在控制层里进行,个人认为这些操作做好在model里统一进行为好,这样control里就比较干净清晰了它做一些页面控制和参数获取就行,model也专用来做数据层操作。
其实也很简单,可将findsql重新在model里封装一个方法就可以了,我这里用 myFindSql来封装它
封装后的model:
class guestbook extends spModel
{
var $pk = "id"; //
var $table = "guestbook"; //
function myFindSql($id){
return $this->findSql("select * from guestbook where id = 10 ");
}
}
在control里使用:
function indexOne(){
$guestbook = spClass("guestbook");
$id = 10 ;
//$this->results = $guestbook->findSql("select * from guestbook where id = $id "); // 原来直接使用findsql。
$this->results = $guestbook->myFindSql($id); // 调用model的方法。
$this->display("green/index.html");
}
2011-12-26 21:30:37