Magento: Detect if admin is logged in in frontend pages

后端 未结 12 603
轻奢々
轻奢々 2021-02-04 00:09

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

12条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 00:47

    The key to be able to use:

    // Ensure we're in the admin session namespace for checking the admin user..
    Mage::getSingleton('core/session', array('name' => 'adminhtml'))->start();
    
    $admin_logged_in = Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn();
    
    // ..get back to the original.
    Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start();
    

    is that the controller must extends Mage_Adminhtml_Controller_Action

    than you can use this code in the preDispatch function.

    And setup the routers for this controller in the admin section of your config.xml.

提交回复
热议问题