Magento:如何检查管理员是否在模块控制器中登录? [英] Magento : How to check if admin is logged in within a module controller?

查看:98
本文介绍了Magento:如何检查管理员是否在模块控制器中登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Magento模块.在控制器内,我想检查管理员是否已登录.因此,只有在有管理员登录的情况下,控制器才可以访问.

I'm creating a Magento Module. Within the controller, I want to check if an admin is logged in or not. So the controller only will be accessible if there is a logged in admin.

我正在尝试在控制器上使用此代码.

I'm trying to use this code on my controller.

Mage::getSingleton('core/session', array('name' => 'adminhtml')); 
$session = Mage::getSingleton('admin/session');

// Use the 'admin/session' object to check loggedIn status
if ( $session->isLoggedIn() ) {
   echo "logged in";
} else {
   echo "not logged in";
}

但是即使我已经登录了magento管理员,我也总是会未登录".

but I always get "not logged in", even if I'm already logged in to the magento admin.

有人可以帮助我解决此问题吗?任何帮助都感激不尽. 谢谢

Can anybody help me to resolve this issue?? any help will be much appreciated. Thanks

推荐答案

那真的很奇怪.我使用几乎完全相同的代码,并且始终有效:

That is really strange. I use almost exactly the same code and it works all the time:

//get the admin session
Mage::getSingleton('core/session', array('name'=>'adminhtml'));

//verify if the user is logged in to the backend
if(Mage::getSingleton('admin/session')->isLoggedIn()){
  //do stuff
}
else
{
  echo "go away bad boy";
}

您是否尝试过var_dumping $ session变量?也许它将帮助您走上正确的路...

Did you try var_dumping the $session variable? Maybe it will help you get on the right track...

这篇关于Magento:如何检查管理员是否在模块控制器中登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆