编程语言
首页 > 编程语言> > php – typo3 extbase:有没有办法将exec_SELECTgetRows结果映射到实体?

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

作者:互联网

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

我会感激任何提示.

解决方法:

您可以通过手动触发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);
}

标签:php,typo3,extbase
来源: https://codeday.me/bug/20190528/1168209.html