Obtain model after redirect

Hi,

I have a problem how could I get a reference to the model after being redirect?


public function actionList()

{

	$form=new Report;


	if(isset($_POST['Report']))

	{

		$form->attributes=$_POST['Report'];

		if( $form->validate() )

			$this->redirect(array('report/show');

	}

	$this->render('list',array('form'=>$form));

}	

	

/**

 * Shows a particular model.

 */

public function actionShow()

{		

	$this->render('show',array('form'=>$form));

}

I used above methods but the $form is not available on the show.php view.

Help me please…

Thx,

Daniel

redirect() makes a completely new page request. Think of it as automatically typing a new URL in the user’s browser and then pressing enter. You will need to define $form in your show action.

Why don’t you use?




if( $form->validate() )

   $this->render(array('report/show'),array('form'=>$form));




I had the same issue with a search form recently, I didn’t want to render the page in place due to URL consistency (I would end up showing the original search form in /search/results instead of just /search if the form wouldn’t validate).

Anyway, I ended up caching the model for 5 seconds and checking for the existence of a cached model on the redirected page. Not really an elegant solution but the best I could come up with for now…