Magento:检测管理员是否在前端页面中登录 [英] Magento: Detect if admin is logged in in frontend pages

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

问题描述

我创建了一个magento扩展程序.我想实现对扩展的访问.该扩展程序在前端创建一个页面,我只希望管理员访问该页面.因此,基本上我需要一些可以检测到管理员是否在前端页面中登录的东西.

I have created a magento extension. I want to implement access to the extension. The extension creates a page in frontend and i want only admin to access that page. So basically i need something that would detect that if admin is logged in in frontend pages.

我尝试了几种解决方案,但注意到似乎可行.

I have tried several solution but noting seem to work .

if(Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn()) echo 'logged in'; else echo 'not logged in';

检查前端是否已登录

Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$adminSession = Mage::getSingleton('admin/session');
$adminSession->start();
if ($adminSession->isLoggedIn()) {
   echo 'logged in';
}

推荐答案

上述解决方案不起作用!

The above solutions doesn't work!

这是一个可行的解决方案(它不是很干净!但是可以在您的应用程序中的phtml视图,模型,控制器或帮助器中的任何地方使用!)

Here is a solution that works ( its not that clean ! but this will work anywhere in your application in phtml view or model or controller or helper ! )

$sesId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false ;
$session = false;
if($sesId){
    $session = Mage::getSingleton('core/resource_session')->read($sesId);
}
$loggedIn = false;
if($session)
{
    if(stristr($session,'Mage_Admin_Model_User'))
    {
        $loggedIn = true;
    }
}
var_dump($loggedIn);// this will be true if admin logged in and false if not

这篇关于Magento:检测管理员是否在前端页面中登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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