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');
}
}
}
Why the msg of the echo appears every time the action is load?
This works for me:
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With