Friday, 11 June 2010

How to set Cookie in symfony?

// cookie getter
$string = $this->getRequest()->getCookie('mycookie');
 
// cookie setter
$this->getResponse()->setCookie('mycookie', $value);
 
// cookie setter with options
$this->getResponse()->setCookie('mycookie', $value, $expire, $path, $domain, $secure);
 
If you want to manipulate cookies outside of an action, you will need to access the Request and Answer objects without shortcut: 
 
$request  = sfContext::getInstance()->getRequest();
$response = sfContext::getInstance()->getResponse();
 
 
Cheers! 

2 comments:

  1. Thanks I'd been looking for this a while

    ReplyDelete
  2. Really helpfull for beginners like me. Thank you.

    ReplyDelete