hi i am using cakephp in this i write the cookie value in controller file. i wanna read that cookie value in view file than how it possible.
A:
I use the SessionComponent and SessionHelper to do this:
In the controller:
$this->Session->write('first_visit', true);
In the view:
if ($session->check('first_visit')) {
$session->del('first_visit');
echo $this->element('quick_intro');
}
You can also use $session->read('value') to read out a value from the session, instead of just checking if it exists.
Oscar
2010-07-16 12:20:33
The question is about Cookie rather than Session.
Nik
2010-07-16 19:20:35
A:
After all CakePHP is a PHP framework, you can read them by $_COOKIE :)
Bear in mind that you should use:
$this->Cookie->write('myValue', $value, false);
in your controller, because otherwise it will be encrypted and it will be hard to use :)
Nik
2010-07-16 19:15:40
A:
You must read it in the controller and set the value to make it available to the view:
$this->set('myValue', $this->Cookie->read('cookieValue'));
Then in the view, you can access the variable $myValue to return the value of 'cookieValue':
<?php echo $myValue; ?>
cdburgess
2010-08-10 19:21:21