title: symfony session not saving
body: <p>I am currently working on a website with a lot a of table.
  Almost all of the table have filters, and since the user don't want to lose all of his filters when he reloads, I am saving the filter in the session.</p>
  
  <p>So far, all of this is working, I run an ajax call everytime the filter changes to save the new filter in the session.
  My issue is when I try to clear the filters.</p>
  
  <p>When the user clicks on the clear button or closes the last filter box, the session key is emptied, and it prints null, but when I reload the page, that last filters are loaded, and the session prints them as if I never removed them.</p>
  
  <p>The function that I use to fill/empty the session:</p>
  
  <pre><code>public function addPersistenceAction(Request $request)
  {
      $parameters = $request-&gt;request-&gt;all();
      $session = $this-&gt;get('session');
      $session-&gt;start();//I tried removing/adding this line but it didn't change anything
  
      //if the key wasn't send, nothing happends
      if (!isset($parameters['storage'])){
          return new JsonResponse(0);
      }
  
      //if no data was send, it removes the key. 
      if(!isset($parameters['data'])) {
          $session-&gt;remove($parameters['storage']);
          // I also tried setting an empty array but it didn't work either
          //$session-&gt;set($parameters['storage'], []);
          return new JsonResponse($session-&gt;all()); // this prints the correct data
      }
  
      //if the data was sent, it is set. This works perfectly
      $session-&gt;set(
          $parameters['storage'],
          $parameters['data']
      );
  
      return new JsonResponse($session-&gt;get($parameters['storage']))
  }
  </code></pre>
  
  <p>The function always returns what I expect it to, but everytime I reload the page, the session still have the last filter. I have tried with different filters and it's always the last one so it can't have been harcoded in my controller.</p>
  
  <p>Funny thing, I have noticed that if I manually run the function that gets the filter data before reloading the page, it shows me the right value, and if I reload after that, the filter are correctly emptied.</p>
  
  <p>So my question: Is there a reason why my session seems to not be saved and is there a way to programatically "force" symfony to save the session data?</p>
  
  <p>some usefull code:<br>
  The function that gets the session data:</p>
  
  <pre><code>/**
   * @param Request $request
   * @return JsonResponse
   */
  public function getSessionDataAction(Request $request){
      $parameters = $request-&gt;request-&gt;all();
      $session = $this-&gt;get('session');
      $session-&gt;start();
  
      if (!empty($parameters['storage'])) {
          $data = $session-&gt;get($parameters['storage'])?:[];
          return new JsonResponse($data);
      }else{
          return new JsonResponse(array('status' =&gt; 'failed', 'message' =&gt; 'storage is mandatory'));
      }
  }
  </code></pre>
  
  <p>My controller function:</p>
  
  <pre><code>/**
   * @param Request $request
   * @return Response
   */
  public function indexAction(Request $request)
  {
      $this-&gt;denyAccessUnlessGranted(RoleVoterHelper::SECTION_USER_VIEW);
  
      $session = $request-&gt;getSession();
  
      //I checked and the session key I use is not touched in this function
      $filterWidgets = $this-&gt;get('dmt.filter.manager')-&gt;getWidgetData('user_filter');
  
      if (!$this-&gt;get('dmt.role_voter')-&gt;getExtGranted(RoleVoterHelper::SECTION_USER_VIEW)) {
          $filterWidgets['company'] = $this-&gt;getDoctrine()-&gt;getRepository('BugTrackerModelBundle:Company')-&gt;findByAuthorities($this-&gt;getUser()-&gt;getAuthorities());
      }
      $authorities = $this-&gt;getDoctrine()-&gt;getRepository('BugTrackerModelBundle:Authority')-&gt;findAll();
      return $this-&gt;render('DMTBundle:User:index.html.twig', [
          'filter_widgets' =&gt; $filterWidgets,
          'usersColumns'   =&gt; $session-&gt;get('usersColumns'),
          'usersSort'      =&gt; $session-&gt;get('usersSort'),
          'isSuperAdmin'   =&gt; $this-&gt;isGranted(UserHelper::ROLE_SUPER_ADMIN),
          'authorities'     =&gt; $authorities,
      ]);
  }
  </code></pre>
  
  <p>The javascript called when the page opens:</p>
  
  <pre><code>$.post(dependencies.bridgeGetUrl, {
      // something like "project_page_filter", the key for the session.
      storage : dependencies.storage
  }).success(function(response){
      dependencies.filterManager.hook(function(app){
          app.scheme = response;
          app.readScheme();
      });
      run(dependencies);
      if(typeof dependencies.callback == "function"){
          dependencies.callback(dependencies.params);
      }
  });
  </code></pre>
  
  <p>the javascript that sends any modification to the session:<br>
  App.scheme is always the current value of the filters</p>
  
  <pre><code>dependencies.filterManager.setLifecycle(["add", "change-value"], function(app) {
      $.post(dependencies.bridgeUrl, {
          storage : dependencies.storage,
          data : app.scheme
      });
  }).setLifecycle(["remove-all", "remove"], function(app) {
      $.post(dependencies.bridgeUrl, {
          storage : dependencies.storage,
          data : app.scheme
      });
  
      $("#filterSubmit").click();
  });
  </code></pre>