开发者

Symfony: trying to retrieve a variable saved using sfContext::getInstance()

开发者 https://www.devze.com 2022-12-31 04:43 出处:网络
i have these methods in module1/actions/actions.class.php: public function executeMethod1(sfWebRequest $request){

i have these methods in module1/actions/actions.class.php:

public function executeMethod1(sfWebRequest $request){

  $a = 10;

  sfContext::getInstance()->set('a', $a);
  return $this->redirect('module1/method2');

}

public function executeMethod2(sfWebRequest $request){

  echo sfContext::getInstance()->get('a开发者_如何学编程');

}

When i execute module1/method1 i get this error:

"The "a" object does not exist in the current context."

Any idea?

Javi


The redirect is telling the browser to load another page which terminates the current action and results in a new request that has a new context.

There are three options here:

  • You could use a forward if you want module1/method2 to be executed as the result of the first request.
  • You could use a flash attribute to pass $a to the next request.
  • You could use a session attribute if $a has to live beyond the next request.

EDIT: You don't need the return statement before the redirect either.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号