2015-04-29 64 views
0

我有一个产品页面在magento,我有一个下拉菜单和一个提交按钮。 当我从下拉菜单中选择一个值并单击提交时,我将该请求发送到magento安装根目录中名为other.php的文件。magento - 包含根文件夹中的php文件

这很好。

在这个页面上,我设置了一个会话变量$ _SESSION ['myGroupID'],并且我已经成功地回显了这一点,所以我知道没关系。

当我转到重定向页面时,$_SESSION['myGroupID']不是持久的。我已在所有必需页面上包含session_start();

我怀疑这是因为我在这里突破了magento的世界,关闭了我在根中创建的php文件,然后再返回到magento世界中的页面。

有人可以告诉我,为了“教”magento,我需要做什么,这个other.php文件是整个设置的一部分,我需要包括什么以允许会话变量持续存在于我的网页?

我看到这个链接看起来是一个类似的问题,但我是Magento的新手,不太了解它中的信息。

https://magento.stackexchange.com/questions/8147/adding-magentos-required-structure-to-a-php-file

回答

1

您需要在您的外部文件的顶部添加下面的代码。

<?php 
require_once('app/Mage.php'); //Path to Magento 
umask(0); 
Mage::app('default'); 
//Get the session object 
$session = Mage::getSingleton("core/session", array("name"=>"frontend")); 
$groupid = $session->getMyGroupId(); 

您需要在另一个页面来定义像

$data = 'GroupId'; 
Mage::getSingleton('core/session')->setMyGroupId($data); 

您的会议让我知道如果您有任何问题。

+0

太棒了 - 今晚我会试试这个。我很欣赏这种回应 - 谢谢! – dstewart101

+0

这似乎工作,但我遇到了使用magento方法保留会话值的另一个问题。我已经创建了一个新问题 - 感谢帮助这个问题。 – dstewart101

+0

新问题在这里! http://stackoverflow.com/questions/29955725/session-wont-persist-on-reload-in-magento – dstewart101