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 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式