Zend Db Table Abstract fetchRow 向其中添加新对象

发布于 2024-09-13 12:02:07 字数 512 浏览 10 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅窗月明清似水 2024-09-20 12:02:07

如果您的表是不同类型文件的数据集,那么您需要控制它们的水合方式 - 即。查询返回哪些对象。为此,您需要为表创建自己的 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).

原野 2024-09-20 12:02:07

尝试

$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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文