cakephp findAll

字体大小: 中小 标准 ->行高大小: 标准

获取你需要的数据


findAll
  string $conditions
  array $fields
  string $order
  int $limit
  int $page
  int $recursive


[$conditions Type: string] 检索条件,就是sql中where子句,就像这样 $conditions = "race = 'wookie' AND thermal_detonators > 3"。

[$fields Type: array] 检索属性,就是投影,指定所有你希望返回的属性。 (译注:这里我没有使用字段这个亲SQL的名字而是用了属性这个亲对象的名字,我相信很多PHPer更熟悉基于Sql和DTO的开发模式,但是引入Model的一个初衷就是将关系数据库转换为对象操作,所以投影查询应该理解为检索对象的某些属性)

[$order Type: string] 排序属性 指定了oder by的属性名 [TODO:check whether the multiple order field be supported]

[$limit Type: int] 结果集数据条目限制

[$page Type: int] 结果集分页index,默认为返回第一页

[$recursive Type: int] 递归当设为大于1的整数时,将返回该model关联的其他对象。(译注:如果你使用过类似于Hibernate这样的ORM工具的话,不难理解这个属性就是 LazyLoad属性,但也不完全等同,数字的值代表级联查询的层次数,例如这样,user.country.city.address.id)

 

function testfindall(){
     $this->autoRender = false;
     
     $result =$this->Operator->findAll($con="status =0 and email='hailang@21cn.com'",array('loginname',id),'order by id desc',10,1,1);
   
                              
     echo "<pre>";
    print_r($result);
     echo "</pre>";
     
    }

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/782.html