magento - 在根文件夹中包含 php 文件
magento - including php file in the root folder
我在 magento 中有一个产品页面,其中有一个下拉菜单和一个提交按钮。
当我从下拉菜单中选择一个值并单击提交时,我将请求发送到 magento 安装根目录中名为 other.php 的文件。
这一切都很好。
在这个页面上我设置了一个会话变量 $_SESSION['myGroupID'] 并且我已经成功地回应了这个所以我知道没关系。
当我重定向回引用页面时,$_SESSION['myGroupID']
没有持续存在。我已将 session_start();
添加到所有必填页面。
我怀疑这是因为我在这里脱离了 magento 的世界,转到我在根目录中创建的 php 文件,然后又返回到 magento 世界中的一个页面。
有人可以告诉我我需要做什么才能 "teach" magento 这个 other.php 文件是整体设置的一部分,以及我需要包含哪些内容才能允许会话要在我的页面中保留的变量?
我看到这个 link 看起来是一个类似的问题,但我是 Magento 的新手,不太了解其中的信息。
https://magento.stackexchange.com/questions/8147/adding-magentos-required-structure-to-a-php-file
您需要在外部文件的顶部添加以下代码。
<?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);
如果您有任何问题,请告诉我。
我在 magento 中有一个产品页面,其中有一个下拉菜单和一个提交按钮。 当我从下拉菜单中选择一个值并单击提交时,我将请求发送到 magento 安装根目录中名为 other.php 的文件。
这一切都很好。
在这个页面上我设置了一个会话变量 $_SESSION['myGroupID'] 并且我已经成功地回应了这个所以我知道没关系。
当我重定向回引用页面时,$_SESSION['myGroupID']
没有持续存在。我已将 session_start();
添加到所有必填页面。
我怀疑这是因为我在这里脱离了 magento 的世界,转到我在根目录中创建的 php 文件,然后又返回到 magento 世界中的一个页面。
有人可以告诉我我需要做什么才能 "teach" magento 这个 other.php 文件是整体设置的一部分,以及我需要包含哪些内容才能允许会话要在我的页面中保留的变量?
我看到这个 link 看起来是一个类似的问题,但我是 Magento 的新手,不太了解其中的信息。
https://magento.stackexchange.com/questions/8147/adding-magentos-required-structure-to-a-php-file
您需要在外部文件的顶部添加以下代码。
<?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);
如果您有任何问题,请告诉我。