cakephp:Cookie看不到 [英] cakephp: Cookie does not read at view

查看:207
本文介绍了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>].

这篇关于cakephp:Cookie看不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆