Magento怎么设置和使用Cookie和Session
答案:1 悬赏:50 手机版
解决时间 2021-03-26 19:47
- 提问者网友:蓝莓格格巫
- 2021-03-26 02:31
Magento怎么设置和使用Cookie和Session
最佳答案
- 五星知识达人网友:毛毛
- 2021-03-26 03:53
magento中cookie和session是已经封装了的
Magento的核心对象-Mage_Core_Model_Cookie & Mage_Core_Model_Session
Mage_Core_Model_Cookie,这个对象主要是用来设置cookie的,具体方法如下:
01 public function getDomain();
02 public function getConfigDomain();
03 public function getPath();
04 public function getLifetime();
05 public function setLifetime();
06 public function getHttponly();
07 public function isSecure();
08 public function set();
09 public function renew();
10 public function get();
11 public function delete();
具体设置COOKIE的方法如下:
01
12 public function set($name, $value, $period = null, $path = null, $domain = null, $secure = null, $httponly = null)
13 {
14 }
使用很方便,设置一个Cookie,只要设置cookie的名字和value就可以了,其他的都可以省略
1 $cookieModel = Mage::getModel(‘core/cookie’);
2 $cookieModel->set($name, $value, $period, $path, $domain, $secure, $httponly);
3 //也可以
4 Mage::getSingleton(“core/cookie”)->set(“name”,”value”);
获取cookie主要用到的是get()
01
04 Mage::getModel(‘core/cookie’)->get($name);
05
08 Mage::getModel(‘core/cookie’)->get();
09
13 Mage::getModel(‘core/cookie’)->get($name, $path, $domain, $secure, $httponly);
也可以通过下面的代码来获取cookie的expire Date, path, domain, secure, httponly
1 $cookieExpires = Mage::getModel(‘core/cookie’)->getLifetime();
2 $cookiePath = Mage::getModel(‘core/cookie’)->getPath();
3 $cookieDomain = Mage::getModel(‘core/cookie’)->getDomain();
4 $cookieSecure = Mage::getModel(‘core/cookie’)->isSecure();
5 $cookieHttponly = Mage::getModel(‘core/cookie’)->getHttponly();
Session的设置
Mage_Core_Model_Session,这个对象的使用很简单
Mage::getSingleton(‘core/session’)->setXXXX(value);
Magento的核心对象-Mage_Core_Model_Cookie & Mage_Core_Model_Session
Mage_Core_Model_Cookie,这个对象主要是用来设置cookie的,具体方法如下:
01 public function getDomain();
02 public function getConfigDomain();
03 public function getPath();
04 public function getLifetime();
05 public function setLifetime();
06 public function getHttponly();
07 public function isSecure();
08 public function set();
09 public function renew();
10 public function get();
11 public function delete();
具体设置COOKIE的方法如下:
01
12 public function set($name, $value, $period = null, $path = null, $domain = null, $secure = null, $httponly = null)
13 {
14 }
使用很方便,设置一个Cookie,只要设置cookie的名字和value就可以了,其他的都可以省略
1 $cookieModel = Mage::getModel(‘core/cookie’);
2 $cookieModel->set($name, $value, $period, $path, $domain, $secure, $httponly);
3 //也可以
4 Mage::getSingleton(“core/cookie”)->set(“name”,”value”);
获取cookie主要用到的是get()
01
04 Mage::getModel(‘core/cookie’)->get($name);
05
08 Mage::getModel(‘core/cookie’)->get();
09
13 Mage::getModel(‘core/cookie’)->get($name, $path, $domain, $secure, $httponly);
也可以通过下面的代码来获取cookie的expire Date, path, domain, secure, httponly
1 $cookieExpires = Mage::getModel(‘core/cookie’)->getLifetime();
2 $cookiePath = Mage::getModel(‘core/cookie’)->getPath();
3 $cookieDomain = Mage::getModel(‘core/cookie’)->getDomain();
4 $cookieSecure = Mage::getModel(‘core/cookie’)->isSecure();
5 $cookieHttponly = Mage::getModel(‘core/cookie’)->getHttponly();
Session的设置
Mage_Core_Model_Session,这个对象的使用很简单
Mage::getSingleton(‘core/session’)->setXXXX(value);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯