使用过thinkphp都知道其curd的连贯操作方式:
$model->where($map)->limit()->select();
这么调用是不是很酷^_^
其实where、limit、select是类中普通的方法,不同的是中间的那些加了一个return $this
这种方式常用的场景是通过方法设置参数或者处理(不需要返回值)
<?php
class example {
var $where;
var $limit;
function where($where) {
$this->where = $where;
return $this;
}
function limit($limit) {
$this->limit = $limit;
return $this;
}
function select() {
print("where: {$this->where},limit: {$this->limit}");
}
}
$model = new example;
$model->where("id=12 and cid=1")->limit("(0,5)")->select();
?>