This is driving me nuts! I'm trying to set a new cookie value:
protected function setCookie($cookieName = null, $cookieVal = null)
{
$model = Mage::getModel('core/cookie');
$cookieVal = Mage::app()->getRequest()->getParam('source');
var_dump('Value: ' . $cookieVal);
$theCookie = $model->set($cookieName, $cookieVal);
return $this;
}
The var_dump
spits out: string(17) "Value: testpeanut"
. However, the cookie is never created.
I'm obviously looking for a URL query string like so: domain.com?source=testpeanut
. If I replace the $cookieVal =
line with the following:
$cookieVal = 'hardcoded_values_work';
Then it works as expected and the cookie is set. What the problem is? Thanks.
~ Edit ~
This code is part of a model observer class. Obviously, I haven't included all of my code here for cleanliness sake. If I get all the params and dump the array, my param is present and has a value:
$cookieVal = Mage::app()->getRequest()->getParams();
var_dump($cookieVal);
Also, if I pass a non-null parameter as a second argument to the getParam()
method, it also works:
Mage::app()->getRequest()->getParam($param, 'i_can_see_this');
I need to check if the param is supplied in the URL, which is why that method won't work long-term. I've been tailing all the logs - no errors or warnings at all.