西部数码主机 | 阿里云主机| 虚拟主机 | 服务器 | 返回乐道官网
当前位置: 主页 > php教程 > magento教程 >

Magento的session用法和注册变量的用法

时间:2016-01-29 20:30来源:未知 作者:好模板 点击:
1. Magento: Get and set variables in session To set a Magento session variable: Php代码 $myValue = Hello World; Mage::getSingleton(core/session)-setMyValue($myValue); To Retrieve: Php代码 $myValue = ; $myValue=Mage::getSingleton(core/se

1. Magento: Get and set variables in session

To set a Magento session variable:
Php代码
$myValue = ‘Hello World’;
Mage::getSingleton(‘core/session’)->setMyValue($myValue);

To Retrieve:
Php代码
$myValue = ”;
$myValue=Mage::getSingleton(‘core/session’)->getMyValue();

To Unset:
Php代码
Mage::getSingleton(‘core/session’)->unsMyValue();

或者
Php代码
/* Core Session */
Mage::getSingleton(‘core/session’)->setYourVariable(‘data’);
$Data = Mage::getSingleton(‘core/session’)->getYourVariable();

/* Customer Session */
Mage::getSingleton(‘customer/session’)->setYourVariable(‘data’);
$Data = Mage::getSingleton(‘customer/session’)->getYourVariable();

/* Admin Session */
Mage::getSingleton(‘admin/session’)->setYourVariable(‘data’);
$Data = Mage::getSingleton(‘admin/session’)->getYourVariable();

2. Magento’s Registry Pattern

The three registry methods are
Php代码
Mage::register
Mage::unregister
Mage::registry

The register method is how you set a global-like variable.
Php代码
Mage::register(‘some_name’, $var);

Then, later in the request execution, (from any method), you can fetch your variable back out
Php代码
$my_var = Mage::registry(‘some_name’);

Finally, if you want to make you variable unavailable, you can use the unregister method to remove it from the registry.
Php代码
Mage::unregister(‘some_name’);

(责任编辑:好模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容