问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/2896274/symfony-trying-to-retrieve-a-variable-saved-using-sfcontextgetinstance