typo3 extbase:有没有办法将exec_SELECTgetRows结果映射到实体?

时间:2015-12-22 07:14:56

标签: php typo3 extbase

我必须对我的数据库进行相当复杂的查询,并且看起来extbase查询无法满足我的需求(例如,我需要所有带有文章计数> 0的类别)。所以我创建了一个查询并使用exec_SELECTgetRows执行它 - 现在,有没有办法将结果映射回实体?

我会感激任何提示。

1 个答案:

答案 0 :(得分:6)

您可以通过手动触发PropertyMapper来实现此目的。检查一下Flow docs。这个概念在ExtBase中是1:1相同。

您的案例中的一些示例代码可能如下:

$objectStorage = $this->objectManager->get(ObjectStorage::class);
$propertyMapper = $this->objectManager->get(PropertyMapper::class);
$dataArray = $this->db->exec_SELECTgetRows(...);
foreach($dataArray as $data) {
    $dataObject = $propertyMapper->convert($data, \Your\Custom\Object::class);
    $objectStorage->attach($dataObject);
}