1

오류 : 페이징 장치의 요소가 개체 (배열 아님)입니다. var_dump($records) :Zend Paginator + Table Gateway : 오류

object(Records\Model\Records)#240 (11) { ["id"]=> NULL ["name"]=> string(9) "5453gdfgd" ["email"]=> string(16) "[email protected]" ["homepage"]=> string(0) "" ["text"]=> string(5) "ghjkj" ["image"]=> string(5) "Array" ["file"]=> string(0) "" ["ip"]=> NULL ["browser"]=> NULL ["date"]=> string(19) "2013-03-05 23:24:49" ["inputFilter":protected]=> NULL } 
object(Records\Model\Records)#241 (11) { ["id"]=> NULL ["name"]=> string(9) "5453gdfgd" ["email"]=> string(16) "[email protected]" ["homepage"]=> string(0) "" ["text"]=> string(5) "ghjkj" ["image"]=> string(5) "Array" ["file"]=> string(0) "" ["ip"]=> NULL ["browser"]=> NULL ["date"]=> string(19) "2013-03-05 23:23:37" ["inputFilter":protected]=> NULL } 

컨트롤러 :

protected $recordsTable; 
     public function indexAction() 
     { 
      $field = (string) $this->params()->fromRoute('field', 'date'); 
      $order = (string) $this->params()->fromRoute('order', 'desc'); 
      $array = $this->getRecordsTable()->fetchAll($field, $order); 

      $paginator = new Paginator\Paginator(new Paginator\Adapter\Iterator($array)); 
      $paginator->setCurrentPageNumber($this->params()->fromRoute('page', 1)); 
      $paginator->setItemCountPerPage(2); 
      //print_r($paginator); 
      $vm = new ViewModel(array('records' => $paginator)); 
      return $vm; 
     } 

    public function getRecordsTable() 
     { 
      if (!$this->recordsTable) { 
       $sm = $this->getServiceLocator(); 
       $this->recordsTable = $sm->get('Records\Model\RecordsTable'); 
      } 
      return $this->recordsTable; 
     } 

RecordsTable :보기에서

protected $tableGateway; 

     public function __construct(TableGateway $tableGateway) 
     { 
      $this->tableGateway = $tableGateway; 
     } 

     public function fetchAll($field, $order) 
     { 
      $this->field = $field; 
      $this->order = $order; 
      $resultSet = $this->tableGateway->select(function (Select $select) { 
      $select->columns(array('date', 'name', 'email', 'homepage', 'text', 'image', 'file')); 
      $select->order($this->field.' '.$this->order);   
      }); 
      $resultSet->buffer(); 
      $resultSet->next(); 

      return $resultSet; 
     } 

: 내가 잘못

foreach($records as $record) : ?> 
    <?php var_dump($record); ?> <br /> 
<?php endforeach; ?> 

을 뭐하는 거지? $records을 배열로 만들려면 어떻게해야합니까?

미리 감사드립니다.

답변

0

어느

public function fetchAll($field, $order) 
{ 
    // ... 
    return $resultSet->toArray(); 
} 

아니면보기

, 당신의 foreach 문에 toArray 방법을 사용 ... 그 toArray 방법을 사용하여 결과 세트에서 배열을 반환

<?php foreach($records->toArray() as $record) : ?> 
    <?php var_dump($record); ?> <br /> 
<?php endforeach;  
+0

추가 정보 : 젠드 \ Db \ ResultSet \ Exception \ RuntimeException 파일 : /opt/lampp/htdocs/guest-book/vendor/zendframework/zendframework/library/Z end/Db/ResultSet/AbstractResultSet.php : 265 메시지 : 개체 유형의이 DataSource의 일부 행은 배열로 캐스팅 될 수 없습니다. – Igor

+0

Ah. 모델에 'getArrayCopy()'메소드가 있습니까? '공공 함수 getArrayCopy() { return get_object_vars ($ this); }' – Crisp

+0

네, 그렇습니다 ..... – Igor