Question: I have created a session variable in one controller and I want to access it in another controller. In `loginsuccess` controller I set the session: 

```
$session->set('id',$id);

```

How can I access this variable in another controller?

Answer: 
There is `session` service which you should use:

```
$id = $this->get('session')->get('id');

```

or

```
$this->get('session')->set('id', $id);

```
There is a third way as writing in a comment :

```
use Symfony\Component\HttpFoundation\Session\SessionInterface;

public function indexAction(SessionInterface $session)
{
     $session->set('test', 'yes !');
}

```

This way allows you to get type-hinted variable, this way you can access methods of the Session object in your IDE.