title: Q: [Symfony 4] How may i access to my form's data using session from my controller?
body: <p>I am building a shopping cart application using symfony4.</p>
  <p>I have to create a shopping cart using session in order to store the data of the purchase.</p>
  <p>I created a form that store the item selected. But i don't know how to get this item from my controller.</p>
  <p>First, i have my twig view where i select the element :</p>
  <pre><code>{% extends 'base.html.twig' %}
  
  {% block body %}
      &lt;form action=&quot;{{ path('add_cart', {'id': product.id}) }}&quot; method=&quot;get&quot;&gt;
          &lt;div class=&quot;card&quot; style=&quot;width: 18rem;&quot;&gt;
              &lt;img class=&quot;card-img-top&quot; src=&quot;https://via.placeholder.com/350x150&quot; alt=&quot;Card image cap&quot;&gt;
              &lt;div class=&quot;card-body&quot;&gt;
                  &lt;h5 class=&quot;card-title&quot;&gt;{{ product.name }}&lt;/h5&gt;
                  &lt;p class=&quot;card-text&quot;&gt;{{ product.description | raw}}&lt;/p&gt;
                  &lt;p class=&quot;card-text&quot;&gt;{{ product.price }} euros.&lt;/p&gt;
                  &lt;select name=&quot;quantity_product&quot; class=&quot;span1&quot;&gt;
                  {% for i in 1..10 %}
                      &lt;option value= &quot;{{ i }}&quot;&gt;{{ i }} &lt;/option&gt;
                  {% endfor %}
                  &lt;/select&gt;
                  &lt;a href=&quot;{{path('add_cart')}}&quot; class=&quot;btn btn-primary&quot; name=&quot;validate_product_button&quot;&gt;Ajouter au panier&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;    
  {% endblock %}
  </code></pre>
  <p>then, here is my CartController :</p>
  <pre><code>&lt;?php
  
  namespace App\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  use Symfony\Component\Routing\Annotation\Route;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\HttpFoundation\Session\SessionInterface;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Session\Session;
  use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
  use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  
  
  class CartController extends AbstractController
  {
      
      /**
       * @Route(&quot;/cart&quot;, name=&quot;cart&quot;)
       */
      public function index()
      {
          
          $productId = $_POST['id_product'];
          
          return $this-&gt;render('cart/index.html.twig', [
              'id_product' =&gt;$productId
          ]);
          
      }
      /**
       * @Route(&quot;/addCart&quot;, name=&quot;add_cart&quot;)
       */
  
       public function addProductToCart(Request $request)
       {
  
          $session = new Session(new NativeSessionStorage(), new AttributeBag());
  
          $session-&gt;set('cart', array());
  
          $cart = $session-&gt;get('cart');
          
          return $this-&gt;render('cart/index.html.twig');
       }
      
  }
  </code></pre>
  <p>My question is simple :  how should i use the session element in order to get the element (id_product, quantity_product) from the previous form ?</p>
  <p>I saw several answers using symfony 2 or 3. But many changes have come so far in symfony 4 and i simply don't know how to use it.</p>