Symfony:在动作之间传递参数(使用重定向) [英] Symfony: pass parameter between actions (with a redirect)

查看:60
本文介绍了Symfony:在动作之间传递参数(使用重定向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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')))

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

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

推荐答案

为什么不在重定向前使用会话来存储值,然后在重定向后的其他操作中获取它们?喜欢:

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
  }
}

这篇关于Symfony:在动作之间传递参数(使用重定向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆