
php中有 $this->table('classes')->where('id='.$id)->find(); 请问如何理解?能不否给出个实例来
展开全部
class a{
private $table;
private $where;
public function table($tableName){
$this->table = $tableName;
return $this;
}
public function where($where){
$this->where = $where;
return $this;
}
public function find(){
$sql = "select * from".$this->$table."where ".$this->where;
}
}
}
基本上是这种 其实就是return $this;这会返回当前的类的对象引用 所以你$this->table('classes')->where()继续执行where方法
private $table;
private $where;
public function table($tableName){
$this->table = $tableName;
return $this;
}
public function where($where){
$this->where = $where;
return $this;
}
public function find(){
$sql = "select * from".$this->$table."where ".$this->where;
}
}
}
基本上是这种 其实就是return $this;这会返回当前的类的对象引用 所以你$this->table('classes')->where()继续执行where方法
追问
对,就是这种用法,我自己在写时没有注意 return $this,所以怎么也没弄明白。可能是疏忽,find()里的$this->$table应该去改为$this->table吧。我已经提高了分数。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询