php - Typo3:PersistenceManager persistAll() 在将对象添加到存储库后创建空数据库记录
问题描述
我正在尝试保护数据库中的对象,因此我正在使用 PersistenceManager 类。
在调用之前,persistAll()
我正在向我的存储库添加一个对象。
$newChecklist = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('foo\\bar\\Domain\\Model\\Checklist');
$newChecklist->setNameDE('de');
$newChecklist->setNameEN('en');
$newChecklist->setAuthor('someGuy');
//DebuggerUtility::var_dump($newChecklist); //returns object with correct attribute values
$this->checklistRepository->add($newChecklist);
之后,我像这样使用 PersistenceManager:
$persistenceManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
$persistenceManager->persistAll();
但是这段代码只产生一个空的数据库记录。
我在语法中找不到任何错误。我的文件名都设置正确,Model=>Checklist, Repository=>ChecklistRepository, Controller=>ChecklistController
有谁知道如何解决这个问题?
提前致谢
解决方案
此代码适用于我的 BE 模块:
class MyController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* myRepository
*
* @var \VENDOR\Extension\Domain\Repository\AddressRepository
* @inject
*/
protected $addressRepository = null;
function import() {
$persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
...
$record = GeneralUtility::makeInstance('VENDOR\\Extension\\Domain\\Model\\Address');
$record->setTitle('The Title');
$record->setPid(123);
...
$this->myRepository->add($record);
$persistenceManager->persistAll();
...
}
}
推荐阅读
- python - 如何将用户输入添加到列表并汇总该列表?
- php - 永远不会关闭的多个 .php 进程
- javascript - 为什么我的基本命令输出,但我的嵌入命令没有?
- ffmpeg - /dev/video0:参数无效
- tensorflow - 在 tensorflow 中为另一个较小的模型使用预训练权重
- jsp - 组合多个相同的迭代以呈现相同列表的多个 div
- javascript - How to use onkeyup in quill editor in nuxt js
- swiftui - 如何在 SwiftUI 中将视图的背景设置为灰色背景?
- django - Django Lightsail - 尝试编写只读数据库
- javascript - Cookie 未注册,因此功能未运行