OctoberCMS中如何获取cookie
How to get cookie in OctoberCMS
我被做成了简单的饼干。当用户单击按钮时,它会将当前时间保存在 cookie 中。我的问题是,我需要打印那个日期并设置条件。
我需要在 default.htm 或 navbar.htm
中打印 cookie 当前时间
这就是我要在
中添加的内容
onStart() {
$cookie_time = htmlspecialchars($_COOKIE['get_date_time']);
}
并在 navbar.htm
{{ cookie_time }}
但它没有打印或任何东西。当我签入浏览时,我的网站会正确存储该 cookie。
虽然不是最好的,但是你获取cookie值的方式很好。您的问题在于如何将值传递给 twig 模板。
分配给 $cookie_time
的语法错误。
应该是这样的; $this['cookie_time'] = ...
完整的页面代码是这样的;
url = "/test"
==
public function onStart() {
$this['cookie_time'] = htmlspecialchars($_COOKIE['get_date_time']);
}
==
{{ cookie_time }}
我被做成了简单的饼干。当用户单击按钮时,它会将当前时间保存在 cookie 中。我的问题是,我需要打印那个日期并设置条件。
我需要在 default.htm 或 navbar.htm
中打印 cookie 当前时间这就是我要在
中添加的内容onStart() {
$cookie_time = htmlspecialchars($_COOKIE['get_date_time']);
}
并在 navbar.htm
{{ cookie_time }}
但它没有打印或任何东西。当我签入浏览时,我的网站会正确存储该 cookie。
虽然不是最好的,但是你获取cookie值的方式很好。您的问题在于如何将值传递给 twig 模板。
分配给 $cookie_time
的语法错误。
应该是这样的; $this['cookie_time'] = ...
完整的页面代码是这样的;
url = "/test"
==
public function onStart() {
$this['cookie_time'] = htmlspecialchars($_COOKIE['get_date_time']);
}
==
{{ cookie_time }}