i'm working with symfony and trying to set and get session variable to pass trough a twig template.
I tryied the way is in the symfony example: http://symfony.com/doc/current/components/http_foundation/sessions.html
$session = new Session();
$session->start();
// set and get session attributes
$session->set('name', 'Drak');
$session->get('name');
Twig:
{{ app.session.get('balance') }}
Returns this error message:
An exception has been thrown during the rendering of a template ("Failed to start the session: already started by PHP ($_SESSION is set).")
I check my php.ini and the sessions doesn't start automatycally, also there is no other session live.
I tried this way too:
$session = $this->getRequest()->getSession();
// We store an attribute
$session->set('FrenchTouch', 'Julian');
// in another controller for another request, we retrieve the value of this attribute
$value = $session->get('FrenchTouch');
print_r(array($value));
But returns this other error:
FatalErrorException: Error: Call to a member function get() on a non-object