Symfony: How To set Cookies and Session variable in an include Twig Controller?
<p>This is my first post, then if there is/are any problem let me know :)</p>

<p>I'm building a website using Symfony, but I currently got a problem:
I can't set (or certainly I missed something) cookie and session variable in an include Twig controller <code>{{ render(controller("AcmeCoreBundle:Auth:index")) }}</code> (this controller have to allow 'connection' from each website page)</p>

<p>I have created the form using the entity <code>WhoIsIt</code> and the form type <code>WhoIsIt</code></p>

<pre><code>&lt;?php

namespace Acme\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Cookie;
use Acme\CoreBundle\Form\WhoIsItType;
use Acme\CoreBundle\Entity\WhoIsIt;

class AuthController extends Controller
{
    public function indexAction(Request $request)
    {

        $who = new WhoIsIt;
        $session = $this-&gt;get('session');
        $response = new Response();
        $form = $this-&gt;get('form.factory')-&gt;create(WhoIsItType::class, $who);

        if ($request-&gt;isMethod('POST')) {
          $form-&gt;handleRequest($request);
          if ($form-&gt;isValid()) {
              $whoisit = $form-&gt;getData();
              //I set Cookie and Session variables

              $response-&gt;headers-&gt;setCookie(new Cookie('personality', $whoisit-&gt;getPersonality(), time() + 3600 * 24 * 3));
              $session-&gt;set('personality', $whoisit-&gt;getPersonality());
              $response-&gt;setContent($this-&gt;render('AcmeCoreBundle:Form:Auth.html.twig', array(
                        'form' =&gt; $form-&gt;createView())));
              return $response;
          }
    }

    $cookies = $request-&gt;cookies;
    $who-&gt;setPersonality($this-&gt;setDefault('personality', 'personality.supporter', $cookies, $session));
    $form = $this-&gt;get('form.factory')-&gt;create(WhoIsItType::class, $who);
    $response-&gt;setContent($this-&gt;render('AcmeCoreBundle:Form:Auth.html.twig', array(
        'form' =&gt; $form-&gt;createView())));
    return $response;
}

private function setDefault($element, $default, $cookies, $session)
{
//This fonction help me to define the default value of the form
    if ($session-&gt;has($element))
    {
        return $session-&gt;get($element);
    }
    elseif ($cookies-&gt;has($element))
    {
        return $cookies-&gt;get($element);
    }
    return $default;
}
}
</code></pre>

<p>When I look for the response in Symfony Profiler I just get a POST PARAMETER:</p>

<pre><code>who_is_it   [ personality =&gt; personality.supporter, validate =&gt; ], _token =&gt; 9ACFB8AO53e7M5QMoqyptVhNqOj933SoMYRfKZsNRJ4 ]
</code></pre>

<p>And don't get Cookie nor Session variable named <code>personality</code></p>

<p>I would like to know if it's possible to set cookie/session in a SubRequest?
And If that is possible, what should I change in my code?</p>

<p>I hope you understand my problem :) If you don't, or need more precision please let me know with a comment.</p>

<p>Thank you for your help.</p>