cakephp:Cookie看不到

cakephp:Cookie看不到

问题描述:

在控制器我试试这个,打印$ cookieee,它给我数组

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>";


我的问题

我尝试使用下面打印

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

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


基本上$这是指两个不同的事情在你的控制器和你的视图..因此基本上设置在一个模型,传递给视图,即viewmodel,然后在你的视图中使用。

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.

与PHP不熟悉,因此没有代码,但这是我的理解基于使用MVC框架在.NEt

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

我猜这个问题告诉你在PHP中执行相同操作:如何在cakephp中读取Cookie值查看文件

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

如果你想打破MVC模式,你可以使用: $ _ COOKIE [< cookie_name>]

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