Symfony:在操作之间传递参数(使用重定向)

wha*_*ore 6 parameter-passing symfony-1.4

我从一个动作(executeProcess)重定向到另一个动作(executeIndex).我希望能够传递参数/变量,而不使用GET(例如$this->redirect('index', array('example'=>'true')))

有没有办法直接传递参数而不直接在URL中显示?(例如POST).谢谢.

gui*_*man 6

为什么在重定向之前不使用会话来存储值,然后在重定向后让它们执行其他操作?喜欢:

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
  }
}
Run Code Online (Sandbox Code Playgroud)


Pra*_*ush 6

在两个动作之间传递变量的最佳方法是使用FlashBag

public function fooAction() {
    $this->get('session')->getFlashBag()->add('baz', 'Some variable');
    return $this->redirect(/*Your Redirect Code to barAction*/);
}

public function barAction() {
    $baz = $this->get('session')->getFlashBag()->get('baz');
}
Run Code Online (Sandbox Code Playgroud)

要在Twig模板中使用变量,请使用此-

{% for flashVar in app.session.flashbag.get('baz') %}
    {{ flashVar }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)