doujin4031 2016-10-11 09:18
浏览 68
已采纳

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

I am using TYPO3 7.6.10 and I build my first extension.

I want to add a property to my object in the createAction function of my controller. But the modifications are nt saved.

Here is my code:

/**
 * 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');
}

If I debug my object $newSigil the userID is set, but after adding to the repository the default value will be saved.

I dont understand why. I also try to persist manually with following code, but no solution:

/**
 * @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');
}

I hope the question is understandable

Best regards Felix

  • 写回答

1条回答 默认 最新

  • dongxieyi9115 2016-10-11 10:18
    关注

    Maybe UserID is not correct named? If your database field is called user_id your property for the domain should userId. Only if your database field is called user_i_d it should userID.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据