views:

29

answers:

3

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
The question is about Cookie rather than Session.
Nik
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
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
Did this work for you?
cdburgess