magento中如何获取判断用户登录状态,大部分开发人员直接用
Mage::getSingleton('customer/session')->isLoggedIn()
来判断用户是否登录 比如一般magento开发人员会这样用
<?PHP
//get customer login status ?>
<?php $myStatus = Mage::getSingleton('customer/session')->isLoggedIn() ?>
<?php if($myStatus): ?>
<li><a href="/customer/account/index" title="Customer Register">My account</a> |</li>
<li><?php echo $this->getLayout()->getBlock('header')->getWelcome() ?></li>
<?php else: ?>
<li><a href="/customer/account/index" title="Customer Register">My account</a></li>
<li><a href="/customer/account/create" title="Customer Register">Register</a></li>
<?php endif ?>
但其实在magento里面用户登录状态判断函数早已封装好了. 在app/code/core/Mage/Customer/Helper/Data.php文件中
/**
* Check customer is logged in
*
* @return bool
*/
public function isLoggedIn()
{
return Mage::getSingleton('customer/session')->isLoggedIn();
}
在app/code/core/Mage/Customer/Model/Session.php文件中
/**
* Checking customer login status
*
* @return bool
*/
public function isLoggedIn()
{
return (bool)$this->getId() && (bool)$this->checkCustomerId($this->getId());
}
所以我们可以在全局用
if ($this->helper('customer')->isLoggedIn()) {
// is logon
}
(责任编辑:最模板) |

大气经典红色全静态企业
人气:455
ecshop仿苏宁易购带团购2
人气:1325
ecshop仿1号店2014豪华至尊模
人气:1165
ecshop精仿麦包包2011白金版
人气:1109
韩国SZ服装模板|ecshop服装
人气:670
ecshop简黑色模板,合适仿
人气:554