Silex cookie set

I am using Silex Framework and I am desperately trying to set a cookie. There is no information in the documents, and I tried almost nothing!

Does anyone have the opportunity to experience this, and can provide a small example?

thanks

+4
source share
1 answer

Here is an excerpt from one of my sites that sets a cookie, then serves as a pdf:

$dt = new \DateTime(); $dt->modify("+1 year"); $c = new Cookie("juniorkupon_letoltve", "1", $dt); $r = new Response(file_get_contents(ROOT . "/data/kupon.pdf"), 200, array("Content-Type" => "application/pdf")); $r->headers->setCookie($c); return $r; 

The trick is that you need to create a Response object manually and set a cookie for it. You can configure the response to the output of twig rendering as follows:

 $r = new Response($app["twig"]->render("filename", $params)); 
+7
source

Source: https://habr.com/ru/post/1441411/


All Articles