浏览文章
文章信息
Magento2 前端判断用户是否登陆
14357
1、判断代码
<?php /** * Created by PhpStorm. * User: 秋枫雁飞 * Date: 2019/9/20 * Time: 18:13 * Copyright © 2016 Aiweline. All rights reserved. * See COPYING.txt for license details. */ //url $login_url = $this->getUrl('customer/account/login'); $account_url = $this->getUrl('customer/account/'); //获取sessionb $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->get('Magento\Customer\Model\Session'); //判断登录 if ($customerSession->isLoggedIn()): echo "<a href='$account_url'>My Account</a>"; else: echo "<a href='$login_url'>Login</a>"; endif; ?>