Symfony: pass parameter between actions (with a redirect)

whamsicore picture whamsicore · Mar 8, 2011 · Viewed 16.9k times · Source

I am redirecting from one action (executeProcess) to another (executeIndex). I want to be able to pass a parameter/variable along, without using GET (e.g. $this->redirect('index', array('example'=>'true')))

Is there a way I can directly pass parameters without having it directly displayed in the URL? (e.g. POST). thanks.

Answer

guiman picture guiman · Mar 9, 2011

Why dont you use sessions to store values before redirecting, and then getting them on the other action after you redirected? like:

class ActionClass1 extendes sfActions
{
  public function executeAction1(sfWebRequest $request)
  {
    [..]//Do Some stuff
    $this->getUser()->setAttribute('var',$variable1);
    $this->redirect('another_module/action2');
  }
}

class ActionClass2 extends sfActions
{
  public function executeAction2(sfWebRequest $request)
  {
    $this->other_action_var = $this->getUser()->getAttribute('var');
    //Now we need to remove it so this dont create any inconsistence
    //regarding user navigation
    $this->getUser()->getAttributeHolder()->remove('var');
    [...]//Do some stuff
  }
}