Get Cookie Values ​​Using Zend Framework

Warning: the non-static method Zend_Controller_Request_Http :: getCookie () should not be called statically ..

Try the following to get the cookie values:

$cookieData = Zend_Controller_Request_Http::getCookie($key, $default); 

Is there a better way to do this?

+4
source share
2 answers

getCookie() method is not static; it must be called on an object.

I believe this code is from your controller, so it should look basically like

 $request = $this->getRequest(); $cookieData = $request->getCookie('someCookie', 'default'); 
+16
source

This is a small note, but it can simply help to avoid long, fruitless hours. In my experience, the problems that arise when it is impossible to get the value from $ _COOKIE in zf1 and other frameworks are mainly due to the fact that setCookie is so easy to use that one of them forgets to add the path and domain as follows:

setcookie ('cookieName', 'cookieValue', $ finalExpirationTime, '/', '. yourdomain.com');

and instead do the following:

setcookie ('cookieName', 'cookieValue', $ finalExpirationTime);

This becomes especially annoying, especially when working with Windows with ip instead of real domains. Another thing to look out for is the dot (.) In front of the domain. As indicated in the manual: Older browsers still implementing legacy "RFC 2109 may require leading ones. To match all subdomains.

Hope this helps

+2
source

All Articles