Zum Inhalt springen

Einfaches redirect nach create funktioniert nicht ... ?

Erstellt am 31. Juli 2012 · 4 Antworten · letzte Antwort am 31. Juli 2012

Tags: Frage

mimaxx ·

Hallo,

möchte gern nach dem Anlegen einer neuen Nachricht eine Weiterleitung auf die showAction. Es kommt jedoch folgender Fehler:

#1217839467: Could not ultimately dispatch the request after 101 iterations. Most probably, a @dontvalidate annotation is missing on re-displaying a form with validation errors.

New.html

<f:form method="Post" controller="Posts" action="create"  name="newPosts" object="{newPosts}">
				
	
		<label for="postTitle">Titel</label>
		<f:form.textfield name="postTitle" property="postTitle" /><br>
		
		<label for="forumsId">ForumsID</label>
		<f:form.textfield name="forumsId" property="forumsId" value="{forum.uid}"/><br>	
		
		<label for="forumsId">Text</label>
		<f:form.textarea name="postText" property="postText" rows="20" cols="46" /><br>
	
		<f:form.submit value="Speichern" />
</f:form>

PostsController.php

	/**
	 * action show
	 *
	 * @param Tx_MyForum_Domain_Model_Posts $posts
	 * @return void
	 */
	public function showAction(Tx_MyForum_Domain_Model_Forum $forum, Tx_MyForum_Domain_Model_Posts $posts) {
		$this->view->assign('posts', $posts);
		$this->view->assign('forum', $forum);
	}

	/**
	 * action new
	 *
	 * @param Tx_MyForum_Domain_Model_Posts $newPosts
	 * @dontvalidate $newPosts
	 * @return void
	 */
	public function newAction(Tx_MyForum_Domain_Model_Forum $forum, Tx_MyForum_Domain_Model_Posts $newPosts = NULL) {
		$this->view->assign('newPosts', $newPosts);
		$this->view->assign('forum', $forum);
	}

	/**
	 * action create
	 *
	 * @param Tx_MyForum_Domain_Model_Posts $newPosts
	 * @return void
	 */
	
	public function createAction(Tx_MyForum_Domain_Model_Posts $newPosts, Tx_MyForum_Domain_Model_Forum $forum) {
		$this->postsRepository->add($newPosts);
		$this->flashMessageContainer->add('Your new Posts was created.');
		#$this->redirect('list','Forum');
		$this->redirect('show', NULL, NULL, array('posts' => $newPosts));
		#$this->forward('show', 'Posts', NULL, array('posts' => $newPosts));
	}

Gruss
mimaxx

LuP ·

Hallo,

/**
 * action show
 *
 * @param Tx_MyForum_Domain_Model_Posts $posts
 * @dontvalidate $posts
 * @return void
 */
  public function showAction(Tx_MyForum_Domain_Model_Forum $forum, Tx_MyForum_Domain_Model_Posts $posts) {
    $this->view->assign('posts', $posts);
    $this->view->assign('forum', $forum);
  }

VG,
LuP

mimaxx ·

Hallo LuP,

erstmal Danke für die schnelle Antwort, aber das brachte noch nicht den gewünschten Erfolg.

Habe * @dontvalidate $newPosts in die showAction hinzugefügt. Cache geleert aber immer noch der gleiche Fehler.

Gibt es noch andere Dinge die ich beachten muss? Ist der Aufruf mit

$this->redirect('show', NULL, NULL, array('posts' => $newPosts));

denn korrekt?

Gruss
mimaxx

LuP ·

sorry, habe vorhin wegen redirect nicht gut aufgepasst. Ein anderer Ansatz:

/**
 * show action
 *
 * @return void
 */
public function showAction() {
    $mappingArr = array(
        'posts' => $this->postsRepository,
        'forum' => $this->forumRepository
    );

    foreach($mappingArr as $name => $repo) {
        if($this->request->hasArgument($name)) $this->view->assign($name, $repo->findByUid($this->request->getArgument($name)));
    }
}

VG,
LuP

LuP ·

mein vorheriger Ansatz dürfte auch noch nicht funktionieren. Nimm forward statt redirect:

/**
 * show action
 *
 * @return void
 */
public function showAction() {
    $mappingArr = array('posts', 'forum');

    foreach($mappingArr as $name) {
        if($this->request->hasArgument($name)) $this->view->assign($name, $this->request->getArgument($name));
    }
}

/**
 * action create
 *
 * @param Tx_MyForum_Domain_Model_Posts $newPosts
 * @return void
 */
public function createAction(Tx_MyForum_Domain_Model_Posts $newPosts, Tx_MyForum_Domain_Model_Forum $forum) {
    $this->postsRepository->add($newPosts);
    $this->flashMessageContainer->add('Your new Posts was created.');
    $this->forward('show', NULL, NULL, array('posts' => $newPosts));
}

VG,
LuP