Zf2 - Cómo configurar una cookie
Encontré este temaZend Framework 2 - Concepto de cookie Mientras buscaba información sobre la configuración de cookie en ZF2, pero parece que la información incluida en ese tema no está actualizada.
He intentado el siguiente código:
public function indexAction()
{
$request = $this->getRequest()->getHeaders()->get('Set-Cookie')->foo = 'bar;
$response = $this->getResponse()->getCookie()->baz = 'test';
var_dump($_COOKIE);
...
return new ViewModel();
}
Ambas líneas emiten aviso:
Warning: Creating default object from empty value
Intenté también:
public function indexAction()
{
$cookie = new SetCookie('test', 'value', 60*60*24); // Zend\Http\Header\SetCookie instance
$header = new Cookie(); // Zend\Http\Cookies instance
$header->addCookie($cookie);
...
return new ViewModel();
}
No devuelve ningún error o advertencia, todo parece estar bien, pero cuando intento var_dump ($ _ COOKIE) todavía se muestra nulo.
Sí, mi navegador tiene habilitar las cookies.