php - Symfony, session always return null -



php - Symfony, session always return null -

i'm checking post how access users session service in symfony2? manage session in symfony. want set session variable 1 time user enters specific info , session variable in controller or in twig template, ...

i have in controller:

use symfony\component\httpfoundation\session; class myfirstcontroller { public function myfunction(request $request) { $session = $this->container->get('session'); $session->set('user', array( 'name' => 'my name', 'email' => 'fake@email.com' )); $session->save(); var_dump($session->get('user')); //print null } }

another controller:

use symfony\component\httpfoundation\session; class mysecondcontroller { public function myfunction() { $session = $this->container->get('session'); var_dump($session->get('user')); //print null } }

even trying access session variable after $session->save(); returns null

hope can help me.

edit

using $session = $request->getsession(); or $session = $this->container->get('session'); returns same instance of session on both.

config.yml

session: handler_id: session.handler.native_file save_path: "%kernel.root_dir%/sessions"

another thing is, if don't utilize $session->save(); , after set session $session->get('user'); returns value of user, if reload page , seek again, session null.

you need store sessions under accessible writing directory.

php symfony2 session

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -