magento 设置全局变量 (Session 和 Registry)
2016-03-09 14:31
281 查看
1. Magento: Get and set variables in session
To set a Magento session variable:
To Retrieve:
To Unset:
或者
2. Magento’s Registry Pattern
The three registry methods are
The
Then, later in the request execution, (from any method), you can fetch your variable back out
Finally, if you want to make you variable unavailable, you can use the
it from the registry.
To set a Magento session variable:
$myValue = 'Hello World'; Mage::getSingleton('core/session')->setMyValue($myValue);
To Retrieve:
$myValue = ''; $myValue=Mage::getSingleton('core/session')->getMyValue();
To Unset:
Mage::getSingleton('core/session')->unsMyValue();
或者
/* 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
Mage::register Mage::unregister Mage::registry
The
registermethod is how you set a global-like variable.
Mage::register('some_name', $var);
Then, later in the request execution, (from any method), you can fetch your variable back out
$my_var = Mage::registry('some_name');
Finally, if you want to make you variable unavailable, you can use the
unregistermethod to remove
it from the registry.
Mage::unregister('some_name');
相关文章推荐
- 二叉树实现(java)
- 当BPM业务流程管理遇上制造业
- 禁止textarea框拖动
- HTML--8Window.document对象
- Python Windows环境安装配置,以及Eclipse+Pydev开发
- Android Volley完全解析(一),初识Volley的基本用法
- 阅读笔记《我是一只IT小小鸟》
- 1003-李白打酒
- 设置Ubuntu不进入图形界面
- [LeetCode]201 区间按位与
- 用JavaScript,获取Table中指定的行、列
- 学习进度条
- PHP网站 通过js方式判断是否是手机访问,若是 跳转到手机版网址!
- mybatis批量插入
- 心飞扬~~
- CentOS 6.5 x64 Redis 安装
- Springboot ServletContextListener @Autowired null 解决办法
- centos6.5安装virtualbox虚拟机软件
- 中国版Meerkat来了,趣播手中有一利器,可大幅拉低直播流量
- 再解javascript中的作用域链