Zend Db Table Abstract fetchRow 向其中添加新对象
我有一个 fetchRow,它是这样完成的:
$db = new Database();
$data = $db->fetchRow($db->select()->where('id = ?',$id));
完成了,我想从文件表中检索所有文件,如下所示:
$files = new Database();
$photos = $files->fetchAll($files->select()->where('id = ?',$data->id));
但它返回两个不同的对象,如何将其添加到仅一个对象?
如果我这样做:
$this->view->photos = $photos;
$this->view->data = $data;
它可以工作,但是如何合并数据中的照片?
谢谢并致以诚挚的问候。
I have a fetchRow, that is done like it:
$db = new Database();
$data = $db->fetchRow($db->select()->where('id = ?',$id));
Done it, I would like 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的表是不同类型文件的数据集,那么您需要控制它们的水合方式 - 即。查询返回哪些对象。为此,您需要为表创建自己的 Rowset 类,并将其设置为 Database 类的属性(假设它是 Zend_Db_Table)。
在此行集类中,您将检查行的水合属性,然后选择使用“数据”或“照片”的类。为了保持一致,您还需要修改表类以处理单个记录的水合作用(即使用 find 方法)。
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