1

エラー:paginatorの要素はオブジェクトです(配列ではありません)。var_dump($records)

object(Records\Model\Records)#240 (11) { ["id"]=> NULL ["name"]=> string(9) "5453gdfgd" ["email"]=> string(16) "igor@bk.ru" ["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) "igor@bk.ru" ["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配列として作成できますか?

前もって感謝します!

4

1 に答える 1

0

toArrayそのメソッドを使用して、結果セットから配列を返します。

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

または、あなたの見解ではtoArray、foreachのメソッドを使用してください

<?php foreach($records->toArray() as $record) : ?>
    <?php var_dump($record); ?> <br />
<?php endforeach;      
于 2013-03-07T12:32:43.943 に答える