chetanspeed511987
chetanspeed511987

Reputation: 2025

cakephp: Cookie does not read at view

in controller i try this, and print $cookieee,its give me array

$this->Cookie->write('User', $cookie, true, '+2 weeks');

$cookieee = $this->Cookie->read('User')
echo "<pre>";
print_r($cookieee);
echo "</pre>";

but My question

when i print it any view file ,it doesnt print any values.

i try to print it by using below

echo "<pre>";
print_r($cookie);
echo "</pre>";
echo $cookie['username']."=cokie=";

and

$cookieee = $this->Cookie->read('User');
echo "<pre>";
print_r($cookieee);
echo "</pre>";

Upvotes: 1

Views: 1907

Answers (2)

Baz1nga
Baz1nga

Reputation: 15579

your view does not have access to the cookie.. Basically $this is referring to two different things in the case of your controller and your view.. thus basically set it in a model that is passed to the view i.e viewmodel and then use that in your view.

Not famililar with PHP hence no code but this is my understanding based on using MVC framework in .NEt

I guess this question tells you how to do the same in PHP: how to read cookie value in cakephp view file

and if you want to break the MVC pattern here you could use: $_COOKIE[<cookie_name>].

Upvotes: 3

alumi
alumi

Reputation: 183

There is no Cookie helper in CakePHP, neither a method to access it in View.

You might want to set the cookie to a variable in controller, and then access that variable in corresponding view.

Upvotes: 2

Related Questions