Powermail 保存数据整理器中的 sys_category

问题描述

我想在自己的extbase扩展的数据表中写入powermail数据。该表单提供了一个 sys_category 的 uid,我想将其保留在我的扩展中。

我的终结者中的相关行:

$obj = GeneralUtility::makeInstance('Vendor\myExt\Domain\Model\ProductRating');
$obj->setName('Huber');
$obj->setPrename('Hans');
// etc.
$this->persistenceManager->add($obj);
$this->persistenceManager->persistAll();

这按预期工作,条目保留在数据表中。但现在我想保留给定的 sys_category。这:

$obj->setCategories(13);  // 13 is the uid of the category

显然不起作用(“'\TYPO3\CMS\Extbase\Persistence\ObjectStorage' 类型的预期参数,'string' 提供)。我需要实现 sys_category 的 ObjectStorage,但我不知道如何实现。

>

非常感谢每一个提示......!

彼得

解决方法

您必须创建一个 ObjectStorage 的新实例(例如 $os = new ObjectStorage();),现在您可以向 objectStorage 添加一个对象。之后,您可以在 setCategories() 函数中使用它。

,

来自 Alex Kellner 的提示为我指明了方向。 我将详细描述它 - 也许有些人会觉得它很有用:

首先注入类别存储库:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository
 * @inject
 */
protected $categoryRepository;

然后创建一个新闻对象存储并附加给定的类别:

$newCategories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage;
$myCategory = $this->categoryRepository->findByUid(85);
$newCategories->attach($myCategory);

当然类别的uid应该从powermail表单派生...

这有效。

谢谢亚历克斯!

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...