Zend Db Table Abstract fetchRow add new objects to it
I have a fetchRow, that is done like it:
$db = new Database();
$data = $db->fetchRow($db->select()->where('id = ?',$id));
Done it, I would li开发者_运维问答ke to retrieve all the files from the file table, like this:
$files = new Database();
$photos = $files->fetchAll($files->select()->where('id = ?',$data->id));
But it returns two different objects, how can I add it to only one object?
If I do:
$this->view->photos = $photos;
$this->view->data = $data;
It works, but how can I merge the photos inside the data?
Thanks and best regards.
If your table is a data set of files of different types then you need to control how they are hydrated - ie. what objects are returned from the query. To do this you need to make your own Rowset class for the table and set it as a propert of the Database class (assuming its a Zend_Db_Table).
In this rowset class you would examine the property of the row as its hydrated and then choose which class to use 'Data' or 'Photo'. To keep things consistent you will also need to modify the table class in order to handle hydration of a single record (ie. using a find method).
try
$db = new Database();
$data = $db->fetchRow($db->select()->where('id = ?',$id));
$files = new Database();
$photos = $files->fetchAll($files->select()->where('id = ?',$data->id));
array_push( $photos, $data);
精彩评论