Extbase:修改后的对象未正确保存在存储库中

Extbase: Modified object does not saved in the repository correctly

我正在使用 TYPO3 7.6.10 并构建了我的第一个扩展。

我想在我的控制器的 createAction 函数中向我的对象添加一个 属性。 但是修改没有保存。

这是我的代码:

/**
 * action create
 *
 * @param \Typo3\LpSurvey\Domain\Model\Sigil $newSigil
 * @param array $answers
 * @internal param Survey $newSurvey
 */
public function createAction(Sigil $newSigil, Array $answers)
{
    $newSurvey = $this->objectManager->get('Typo3\LpSurvey\Domain\Model\Survey');
    $this->userID = $GLOBALS['TSFE']->fe_user->user['uid'];

    //this modifications are saved
    foreach ($answers as $key => $answer) {
        $newSurveyItem = $this->objectManager->get('Typo3\LpSurvey\Domain\Model\SurveyItem');

        $newSurveyItem->setQuestionId($key);
        $newSurveyItem->setValue($answer);

        $newSurvey->addAnswer($newSurveyItem);
    }


    //BUT this modification is not saved
    $newSigil->setUserID($this->userID);

    $newSigil->setSurvey($newSurvey);

    $this->sigilRepository->add($newSigil);

    $this->redirect('list');
}

如果我调试我的对象 $newSigil 用户 ID 已设置,但在添加到存储库后将保存默认值。

我不明白为什么。 我也尝试使用以下代码手动坚持,但没有解决方案:

/**
 * @var \typo3\CMS\Extbase\Persistence\Generic\PersistenceManager
 * @inject
 */
protected $persistenceManager;

public function createAction(Sigil $newSigil, Array $answers)
{
    $newSurvey = $this->objectManager->get('Typo3\LpSurvey\Domain\Model\Survey');
    $this->userID = $GLOBALS['TSFE']->fe_user->user['uid'];


    foreach ($answers as $key => $answer) {
        $newSurveyItem = $this->objectManager->get('Typo3\LpSurvey\Domain\Model\SurveyItem');

        $newSurveyItem->setQuestionId($key);
        $newSurveyItem->setValue($answer);

        $newSurvey->addAnswer($newSurveyItem);
    }



    $newSigil->setUserID($this->userID);
    $newSigil->setSurvey($newSurvey);

    $this->persistenceManager->persistAll();

    $this->sigilRepository->add($newSigil);

    $this->redirect('list');
}

我希望问题是可以理解的

问候菲利克斯

可能 UserID 命名不正确?如果您的数据库字段被称为 user_id,您的域 属性 应该 userId。只有当您的数据库字段被称为 user_i_d 时,它才应该 userID.