magento - 包括根文件夹中的php文件

时间:2015-04-29 10:52:54

标签: php magento session

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

这一切都很好。

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

当我转到重定向页面时,$_SESSION['myGroupID']不会持续存在。我已将session_start();包含在所有必填页面中。

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

有人可以告诉我我需要做些什么来教授" magento这个other.php文件是整体设置的一部分,以及我需要包含什么才能让会话变量在我的页面中保持不变?

我看到这个链接似乎是一个类似的问题,但我是Magento的新手,并且不太了解其中的信息。

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

1 个答案:

答案 0 :(得分: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);

如果您遇到任何问题,请告诉我。