Magento设置和调用Cookie、session

用PHP代码

设置Cookie,有三个参数  cookie名称,cookie值 和有效时间 (cookie名称和cookie值为必填项)

$customer_id = 1;
$setCookie = Mage::getModel('core/cookie')->set('friend', $customer_id, 3600*24);

获取Cookie

$getCookie = Mage::getModel('core/cookie')->get('friend');

设置Session 

$customer_id = 1;
$setSession = Mage::getSingleton("core/session")->setData("friend", customer_id);
//或者
$setSession = Mage::getSingleton("core/session")->setFriend(customer_id);

获取Session

$getSession = Mage::getSingleton("core/session")->getData('friend');
//或者
$getSession = Mage::getSingleton("core/session")->getFriend();

用JS代码

设置Cookie

var customer_id = 1;
Mage.Cookies.set('friend', customer_id)

获取Cookie

Mage.Cookies.get('friend');

 

你可能感兴趣的:(Magento,JS,PHP)