Php 如何在magento中获取loggedin用户会话?
我创建了一个模块,显示用户列表。如果用户登录到管理面板,我想显示该页面Php 如何在magento中获取loggedin用户会话?,php,magento,Php,Magento,我创建了一个模块,显示用户列表。如果用户登录到管理面板,我想显示该页面 // world.php <?php namespace Pulsestorm\HelloWorldMVVM\Controller\Hello; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\App\Action\Context; class World extends \Magento\Framework\App\Ac
// world.php
<?php
namespace Pulsestorm\HelloWorldMVVM\Controller\Hello;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;
class World extends \Magento\Framework\App\Action\Action
{
protected $pageFactory;
public function __construct(Context $context, PageFactory $pageFactory)
{
$this->pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
var_dump("feererggrerge",$customerSession->isLoggedIn());
var_dump(__METHOD__);
$page_object = $this->pageFactory->create();;
return $page_object;
}
}
//world.php
您可以检查用户是否已登录或未使用此选项
方法1。要检查客户是否登录到网站的任何页面,请执行以下操作:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
// customer login action
}
方法2。要检查客户是否从控制器登录,请执行以下操作:
$this->_objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
// customer login action
}
<?php
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
//not logged in
}else{
// logged in
}
?>
$this->\u objectManager->get('Magento\Customer\Model\Session');
如果($customerSession->isLoggedIn()){
//客户登录操作
}
@如何检查客户是否登录到管理面板检查此链接它不工作,尽管我在服务器上使用ssh,但我没有获取任何错误日志,因此很难调试。您可以检查我是否已添加代码和结构您正在从控制器文件检查。我已经更新了新的方法来检查答案。我希望人们通过magnto管理面板登录,只有它会检查客户也