Removing cookies throws an error
riasvdv opened this issue · comments
Rias commented
When removing a cookie, Craft throws the following error
When checking if you have to remove the cookie, there's the following code:
if ($name == "") {
Craft::$app->request->cookies->remove($name);
}
Shouldn't this be if ($value == "")
?
But if I change that the following error is thrown:
If I change the whole statement to this:
if ($value == "") {
Craft::$app->request->cookies->readOnly = false;
Craft::$app->request->cookies->remove($name);
Craft::$app->request->cookies->readOnly = true;
}
It works, but that seems a bit convulted somehow?
Rias commented
Ah, dove into Yii2 and it seems that when you remove cookies, you have to do it from the response
class and not the request
, so like this:
Craft::$app->response->cookies->remove($name);
Andrew Welch commented
Thanks @Rias500 !
Andrew Welch commented
I've also added try/catch so errors are logged instead of exceptions thrown