I am developing on an old project that uses Symfony 2.8.
I develop locally and in the Twig I can correctly use {{app.user.username}}
or other like {{app.session...}}
. When I deploy it in a staging environment those values are always blank. Then if I deploy it in production , the global app
variable works fine as in local.
Is it possible that the staging env is configured to not to initialize the app
variable? Where can I take a look?
Plus, a strange thing. The same behavior happens also if I make a custom, loading session data from the controller and passing them to the view.
Controller
$session = $this->get('session');
$content = $this->render(
'blocks/logged_user_menu.html.twig',
[
'access_token_sc' => $session->get('access_token')
]
);
View
{{ access_token_sc }}
I've read that I could take a look at Security config but doesn't seem to help.
Thanks to @john Smith comment I found out that this kind of problem is related to session.storage_id
in the config.yml
file. In my case the test config file was using mock_file
that inhibited the session behavior.
Leaving here the explanation for reference: MockFileSessionStorage class
namespace Symfony\Component\HttpFoundation\Session\Storage;
/**
* MockFileSessionStorage is used to mock sessions for
* functional testing when done in a single PHP process.
*
* No PHP session is actually started since a session can be initialized
* and shutdown only once per PHP execution cycle and this class does
* not pollute any session related globals, including session_*() functions
* or session.* PHP ini directives.
*
* @author Drak <drak@zikula.org>
*/
class MockFileSessionStorage extends MockArraySessionStorage
{ ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.