收录日期:2019/06/20 01:21:24 时间:2010-06-17 10:08:32 标签:php,symfony1

I am trying to pass parameters from one action (foo) to another (foobar).

In action foo, I set the arguments thus:

$request->getParameterHolder()->set('arg1', 'alice');
$request->getParameterHolder()->set('arg2', 'bob');

In action foobar, I try to retrieve the params thus:

$arg1 = $request->getParameter('arg1');
$arg2 = $request->getParameter('arg2');

$this->forward404Unless($arg1 && $arg2); //always forwarded

Note: I am aware that I can save the params into the user session variable - but I dont want to do that. I want to pass them as parameters - any ideas how to get this to work?

You can simply try this:

    $this->redirect('module/action2?'.
      http_build_query(array("arg1"=> "alice", "arg2"=>"bob")));

greg0ire's answer sounds like it's what you are asking for but there are a couple of other approaches that might be worth looking at if passing query string parameters isn't a hard requirement.

You could use a forward if you want the foobar action to execute after foo. Unlike a redirect this will live in the same request cycle so you can pass variables without touching the session.

You don't say why you don't want to use the session but there is a halfway house in Symfony: flash attributes. These are stored in the session but are guaranteed not to live beyond the next request which may be a suitable compromise.