class myController extends Controller
{
public function newAction($id)
{
$session = $this->get('session');
if(is_null(($session->get('foo')))){
echo "the variable foo is no set in session";
$session->set('foo', 'bar');
}
}
}
为什么每次加载动作时都会出现回音消息?
答案 0 :(得分:1)
这对我有用:
class SessionTestController extends Controller
{
public function testAction()
{
$session = $this->get('session');
if (is_null($session->get('foo'))) {
$session->set('foo', 'bar');
$responseText = 'foo is null';
} else {
$responseText = 'foo is set';
}
// Use a response object
return new Response($responseText);
}
}