title: how to get the session variable in the view in symfony2
body: <p>Thanks for your valuable suggestions</p>
  
  <p>i have created a login system where i want to store the id's of users in session variables</p>
  
  <p>this is my controller for login system</p>
  
  <pre><code>use Symfony\Component\HttpFoundation\Session\Session;
  
  class successController extends Controller
  {
  
  public function successAction(Request $request)
      {
  
         --some code for form--
         $repository = $em-&gt;getRepository('RepairStoreBundle:users');
          $query = $repository-&gt;auth($name,$password);
        $error="sorry invalid username or password";   
             if($query== false)
              {
                  return $this-&gt;render('RepairLoginBundle:login:login.html.php', array(
              'form' =&gt; $form-&gt;createView(),'error'=&gt;$error,)); 
                  }
          else
          {
              $role=$query[0]['role'];
              $id=$query[0]['id'];
              if($role == 1)
              {
                  $session = new Session();
                  $session-&gt;start();
                  $session-&gt;set('id',$id);
                  $result=$repository-&gt;display();
              return $this-&gt;render('RepairLoginBundle:login:success.html.php',array('result'=&gt;$result,));
              }
              else
              {
               $session = new Session();
               $session-&gt;start();
               $session-&gt;set('id',$id);
              $res= $repository-&gt;edit($id);
          return $this-&gt;render('RepairLoginBundle:login:user.html.php',array('res'=&gt;$res));
  
              }    
          }
  
      }
  
  }
  </code></pre>
  
  <p>when admin logins with role=1 it will render to success.html.php</p>
  
  <p>in this view how can i get the session variable which  i have set in the controller.
  i have used $session->get('id'); 
  it is giving me server error please help with this</p>