Silex set cookie

守給你的承諾、 提交于 2019-12-05 17:31:27

Here's an excerpt from one of my sites that sets a cookie then serves 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 you need to create the Response object manually and set the cookie on that. You can set the response to a twig render output like this:

$r = new Response($app["twig"]->render("filename", $params));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!