我正在zf2中查詢,我找回了object(Zend\Db\ResultSet\HydratingResultSet)
,我必須打開一個foreach
,才能找到屬性。我想在默認情況下獲取對象數組。如何在zend framework 2中返回一個對象數組?
這裏是一些代碼,我有:
工廠
'address-mapper' => function ($serviceManager) {
$mapper = new Mapper\Address();
$mapper->setDbAdapter($serviceManager->get('Zend\Db\Adapter\Adapter'));
$mapper->setEntityPrototype(new Entity\Address);
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
return $mapper;
}
查詢
public function fetchById()
{
$select = $this->getSelect()->where(array('id' => $Id));
return $this->select($select);
}
這讓我回:
object(Zend\Db\ResultSet\HydratingResultSet)[459]
protected 'hydrator' =>
object(Zend\Stdlib\Hydrator\ClassMethods)[415]
protected 'underscoreSeparatedKeys' => boolean true
private 'callableMethodFilter' =>
....
....
任何想法,我需要什麼做?
相關的http://stackoverflow.com/questions/16590174/convert-zend-db-resultset-hydratingresultset-to-array-of-objects/16692849 – lorey