I am trying to store variables in cookies, using the Symfony 1.4 framework. Here is a snippet of my sfAction derived class:
class productActions extends sfActions
{
public function preExecute()
{
$this->no_registration_form = true;
$request = $this->getRequest();
$cookie_value = $request->getCookie('pcatid');
$this->prod_category_id = (!isset($cookie_value)) ? 0 : $cookie_value;
$cookie_value = $request->getCookie('pitid');
$this->product_item_id = (!isset($cookie_value)) ? 0 : $cookie_value;
$cookie_value = $request->getCookie('pcatnm');
$this->product_category_name = (!isset($cookie_value)) ? null : base64_decode ($cookie_value);
$cookie_value = $request->getCookie('pipnm');
$this->product_info_partial_name = (!isset($cookie_value)) ? null : $cookie_value;
$cookie_value = $request->getCookie('protl');
$this->title = (!isset($cookie_value)) ? null : base64_decode ($cookie_value);
}
public function postExecute()
{
$expire = time()+2592000;
$path = '/products/';
$response = $this->getResponse();
$value = $this->prod_category_id;
if (isset($value))
$response->setCookie('pcatid', $value, $expire, $path);
$value = $this->product_item_id;
if (isset($value))
$response->setCookie('pitid', $value, $expire, $path);
$value = base64_encode($this->product_category_name);
if (isset($value))
$response->setCookie('pcatnm', $value, $expire, $path);
$value = $this->product_info_partial_name;
if (isset($value))
$response->setCookie('pipnm', $value, $expire, $path);
$value = base64_encode($this->title);
if (isset($value))
$response->setCookie('protl', $value, $expire, $path);
}
public function executeIndex(sfWebRequest $request)
{
// uses defaults or settings stored in cookies
}
... // other functions that set the required instance member fields
}
I have stepped through the code in a debug session, and I can see that the cookie values are being collated in the sfWebResponse
variable - however, no cookies are being set - and this is demonstrated in the preExecute()
function - all the cookies retrieved have value null.
Why is this happening?
var_dump($_COOKIE)
inside thepreExecute
show your cookies? – j0kvar_dump($_COOKIE)
insidepreExecute()
shows the existing cookies, but crucially, not the ones I am setting in mypostExecute
. – Homunculus ReticullisfWebResponse
send header. So I'm wondering if the tested action send the header properly (I mean, using a normal layout, etc ..) – j0k