在magento中重新加载会话不会持续 [英] Session won't persist on reload in magento
问题描述
我无法在magento中重新加载页面,并且无法保存会话变量.
I am having trouble with reloading a page in magento and not being able to hold a session variable.
这是我项目中的一些代码片段
Here are some code snippets from my project
view.phtml
view.phtml
<?php
//Get the session object
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$groupid = $session->getMyGroupId("myGroupID");
echo $groupid;
这是我查看页面的顶部.有一个下拉菜单,带有一个提交按钮,该菜单转到另一个名为other.php的页面-它将下拉列表的值放入会话变量中
This is at the top of my view page. There is a drop down menu that with a submit button that goes off to another page called other.php - which takes the value of the drop down and puts it into a session variable
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
//Set groupid
$data = $_POST['county_select'];
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->setMyGroupId($data);
header('Location: '.$_SERVER["HTTP_REFERER"]);
?>
这将重定向回带有下拉菜单的页面,并在屏幕上回显正确的值.
This redirects back to the page I was on with the drop down menu and the correct value is echoed out on screen.
现在,如果我仅刷新此页面,则会话变量将消失.好像它尚未设置.有人可以发现我在做什么错吗?如果我再次从下拉菜单中进行选择,一切都会恢复到以前的状态,但是直接刷新意味着没有任何回响可反映出groupid,因此我知道会话变量现在不行了.
Now, if I just refresh this page, the session variable disappears. It's as if it has been unset. Can anyone spot what I am doing wrong please? If I choose from the dropdown menu again, everything comes back fine as before, but a straight refresh means nothing gets echoed out for groupid so I know the session variable is no good now.
谢谢. DS
推荐答案
用以下代码替换view.phtml代码:
replace view.phtml code with this:
echo Mage::getSingleton("core/session", array("name"=>"frontend"))->getMyGroupId();
这篇关于在magento中重新加载会话不会持续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!