2016-05-31 1 views
1

나는 다음과 같은 ZF2에서 쿼리가 : 난 단지 하나의 객체를 반환하고있어 이후 나는 배열 대신이 쿼리에서 개체를 반환 할 수젠드 프레임 워크이 반환 객체

public function BrandWallBrandsById($userId,$brandId,$startDate,$endDate) 
    { 
      $select = new Select(); 
      $select->from(array('p' => $this->table), array('id')); 
      $select->join(array('b' => 'brands'), 'p.brandId = b.id', array('id','name', 'cover', 'slogan', 'startDate', 'homepage')); 
      $select->columns(array(new Expression('SUM(p.points) as points'), "userId", "brandId")); 
      $select->order("p.points desc"); 
      $select->group("p.brandId"); 
      $where = new Where(); 
      $where->notEqualTo("p.points", 0); 
      $where->equalTo("p.userId", $userId); 
      $where->equalTo("p.brandId", $brandId); 
      $where->between("p.time", $startDate, $endDate); 
      $select->where($where); 
      return $this->historyTable->selectWith($select)->toArray(); 

    } 

을 [0] ?? 이 일을 할 수있는 방법이 있습니까?

답변

0

검색어의 행을 예상하는 경우 current()을 사용할 수 있습니다. 다음과 같이 코드의 마지막 줄을 수정하십시오.

$row = $this->historyTable->selectWith($select)->current(); 
if(!$row){ 
    throw new Exception('No row found'); 
} 
return $row; 
관련 문제