Cookie between controllers

1

I created the following cookie in the controller Location:

$cookie = new \Zend\Http\Header\SetCookie('localidade_id', $localidade->getIdentificador(), time() + 3600);         

However, when trying to access it in the controller Contact:

 $getcookie = $request->getCookie();
 $getcookie->offsetGet('localidade_id');

return is NULL. But if access is done in the locality controller, I have a valid value.

This is the first time I use cookies with ZF2, so I do not know if there is anything wrong. If anyone can help me.

    
asked by anonymous 17.03.2015 / 13:54

1 answer

2

I think the problem is path (fourth parameter). By default, the cookie is set to the current directory: /localidade . You would have to set it for the entire domain: / , like this:

$cookie = new \Zend\Http\Header\SetCookie('localidade_id', $localidade->getIdentificador(), time() + 3600, '/');
    
17.03.2015 / 14:09