Kristian
Kristian

Reputation: 1363

Silex clear cookie

I'm using Silex and I'm trying to clear a cookie. The docs provided for Silex about cookie control is poor, so I have relied on Symfony2 - unfortunately I can't get it working!

$shop->match('/expire', function(Request $request) use ($app) {

    $response = new Response();
    $response->headers->clearCookie('order');
    $response = $app['twig']->render('completed.html.twig');

    return $response;

});

In another attempt I tried re-setting the cookie with a negative expire time, but that didnt work either. No errors at all.

Anyone got a clue what I'm doing wrong?

Thanks

Upvotes: 1

Views: 1815

Answers (2)

Oleg Neumyvakin
Oleg Neumyvakin

Reputation: 10272

"remove" is enough for me: $app['session']->remove('order');

Upvotes: -1

igorw
igorw

Reputation: 28239

You are creating a response object, setting the correct headers but then replacing it with a string of the content. Here is what you should do:

$response = new Response();
$response->headers->clearCookie('order');
$response->setContent($app['twig']->render('completed.html.twig'));

return $response;

Upvotes: 5

Related Questions