acid
acid

Reputation: 2149

Symfony 2.1 - Getting Session ID

While trying to migrate from Symfony 2.0 to 2.1, I've found some interesting issue.

I cannot get the native session id, even in the plain, just downloaded Symfony 2.1 copy.

/**
 * @Route("/sess")
 */
public function sessionAction()
{
    $session = $this->getRequest()->getSession();
    return new Response($session->getId());
}

Did something changed significantly there?

Upvotes: 0

Views: 5391

Answers (1)

mgiagnoni
mgiagnoni

Reputation: 3454

Take a look at this document (under app/config/config.yml section)

In Symfony 2.1 session is always started on-demand. So I'd say what you are seeing is the normal behavior. You need to start the session explicitly before you can get the session ID. I've not checked but maybe setting the first variable also starts the session this is because it works after you call set().

Upvotes: 5

Related Questions