First off, I'm not all that familiar with cookies but I know how they work. I've seen quite a few different tutorials with plain PHP code but I'm looking for a solid example of how to store arrays in a cookie using the symfony syntax:
$this->getResponse()->setCookie('myCookie', $data);
You can't just pass in an array since it expects a string. Is the only way to do it to serialize an array first?
Are there any other options while storing data in a cookie?
If you really need to store it in a cookie and not in a session, you can use serialization:
$this->getResponse()->setCookie('myCookie', serialize($data));
$data = unserialize($this->getRequest()->getCookie('myCookie'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With