Hallo Leute
Ich habe ein ganz gewöhnliches Fluid-Formular. Nach dem Absenden wird das jeweilige Objekt doppelt in die DB geschrieben... kennt jemand dieses Problem?
Fluid Template:
<f:form method="post" action="create" name="newComment" object="{newComment}">
<div class="comment-item-new-name">
<f:form.hidden property="contentid" value="{contentid}" />
<f:form.textbox size="15" property="username" value="Name" />
</div>
<div class="comment-item-new-text">
<f:form.textarea property="comment" value="Kommentar schreiben..." cols="49" rows="7" />
</div>
<f:form.submit value="Absenden" />
</f:form>
showallAction (Listet die Kommentare und zeigt das Formular)
/**
* showall action
* shows all comments
*
* @param integer $id
* @return void
*/
public function showallAction(Tx_PnContentcomments_Domain_Model_Comment $newComment = NULL) {
$id = intval($this->request->getArgument('id'));
$comments = $this->commentRepository->findAllByContent($id);
$count = count($comments);
$this->view->assign('comments', $comments);
$this->view->assign('count', $count);
$this->view->assign('newComment', $newComment);
$this->view->assign('contentid', $id);
}
createAction:
/**
* action create
* creates a new comment
*
* @param Tx_PnContentcomments_Domain_Model_Comment $newComment
* @return void
*/
public function createAction(Tx_PnContentcomments_Domain_Model_Comment $newComment) {
$newComment->setCreatedate(time());
$this->commentRepository->add($newComment);
$this->redirect('showall','Comment',null, array('id' => $newComment->getContentid()));
}
Am Ende der createAction findet ein normaler redirect zur showallAction statt. Dort werden die Kommentare aufgelistet und wieder das Formular gezeigt.
Gruss
Oli