开发者

Get Cookie values with Zend Framework

开发者 https://www.devze.com 2023-01-15 21:10 出处:网络
Warning: Non-static method Zend_Controller_Request_Http::getCookie() should not be called stati开发者_如何学JAVAcally in..

Warning: Non-static method Zend_Controller_Request_Http::getCookie() should not be called stati开发者_如何学JAVAcally in..

Iam trying the following to get Cookie values:

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

is there an better way to this?


getCookie() method is not static, it should be called on an object.

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

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


This is a slight side note, yet it may just well help avoid long fruitless hours. From my experience, the problems that occur when one cannot retrieve value from $_COOKIE in zf1 and other frameworks occur mostly because setCookie is so easy to use one forgets to add the path and the domain like so:

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

and instead do this:

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

This gets real annoying especially so when working on Windows with ip's instead of actual domains. Another thing to look out for would be the dot (.) in front of the domain. As stated in the manual: Older browsers still implementing the deprecated » RFC 2109 may require a leading . to match all subdomains.

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消