I followed this and set it up in my AppController.php
since the cookie should be created from wherever the user first hits the entire website:
use Cake\Http\Cookie\Cookie;
use Cake\Http\Cookie\CookieCollection;
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
.....
$cart_cookie = (new Cookie('cart'))
->withValue([])
->withExpiry(new \DateTime('+1 year'));
$cookies = new CookieCollection([$cart_cookie]);
}
}
Now how can I access this cookie in say CartController.php so I can modify its value? I tried accessing $this->cookies
or $cookies
but it says it doesn't exist. Maybe I missed something in the CakePHP book, but I'm not finding a solution or example.