Cookies

Cookie support is available through dependency injection (DI). Cookie functionality can be accessed by using the $container->cookies container.

Setting cookies

$app->get('/setcookie', function ($request, $response) {
    // $container is in router available as $this
    $response = $this->cookies->setCookie('some_cookie', 'some cookie value', 3600);
    return $response;
});

Reading cookies

$app->get('/readcookie', function ($request, $response) {
    // all cookies
    $allCookies = $request->getCookieParams();

    // individual cookie
    $someCookie = $this->cookies->some_cookie;

    // do something here...
    ....

    return $response;
});

Deleting cookies

$app->get('/cookiedelete', function ($request, $response) {
    $response = $this->cookies->deleteCookie('some_cookie');
    return $response;
});
Last update: January 18th at 6:00pm