Identify admin or frontend request in magento?

IDENTIFY ADMIN OR FRONTEND REQUEST IN MAGENTO

How can we identity or differentiate between admin or frontend code execution or request?

If you are hard core developer then surely you will be required this function now and then. And in this case, our recommendation is to add this function in your core helper class because then you can use this function from more than one module.

Here are the two functions we have written, you can use either of them, this function will return true if you are on admin or executing the code at admin end of the site.

public function isAdmin()
{
    if(Mage::getDesign()->getArea() == 
               Mage_Core_Model_Design_Package::DEFAULT_AREA){
        return false;
    }
    return true;
}

or

public function isAdmin()
{
    if(Mage::app()->getStore()->isAdmin()){
        return true;
    }

    if(Mage::getDesign()->getArea() == 'adminhtml'){
        return true;
    }
    return false;
}

Hope this article helped you in some way. Please leave us your comment and let us know what do you think?

3 thoughts on “Identify admin or frontend request in magento?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.