Magento教程 59:如何在Magento使用Session?

一般而言,在网站中使用PHP函数设立Session,在Magento可以使用已经定义的函数来使用Session,我们将用几个简单的范例进行说明:

Magento教程 59:如何在Magento使用Session?
Magento教程 59:如何在Magento使用Session?

 

设置Session

//输入你所要记录的Session名称与值
//此范例Session的名称是TestString,值为欧斯瑞Astralweb
Mage::getSingleton('core/session')->set TestString('欧斯瑞Astralweb');

取得Session值

//使用get取得已设立Session的值
//此范例以取得名称为TestString 的Session为范例
Mage::getSingleton('core/session')->getTestString('欧斯瑞Astralweb');

清除Session值

//使用unset清除已设立Session的值
//范例为清除名称为TestString 的Session为范例
Mage::getSingleton('core/session')->unsetTestString();

以上就是在Magento中Session的使用方式,希望能协助新手顺利上手Magento!

 

原文:http://www.astralweb.com.tw/how-to-use-session-by-magento/

本文:Magento教程 59:如何在Magento使用Session?

Loading

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.