如何在 cakephp 视图文件中读取 cookie 值 [英] how to read cookie value in cakephp view file

查看:29
本文介绍了如何在 cakephp 视图文件中读取 cookie 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我将 cookie 值写入控制器文件中.我想在视图文件中读取该 cookie 值,而不是如何可能.

in this i write the cookie value in controller file. i wanna read that cookie value in view file than how it possible.

推荐答案

你必须在控制器中读取它并设置值以使其可用于视图:

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'));

然后在视图中就可以访问变量$myValue来返回'cookieValue'的值:

Then in the view, you can access the variable $myValue to return the value of 'cookieValue':

<?php echo $myValue; ?>

这篇关于如何在 cakephp 视图文件中读取 cookie 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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