久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Magento 請求 - 前端還是后端?

Magento Request - Frontend or Backend?(Magento 請求 - 前端還是后端?)
本文介紹了Magento 請求 - 前端還是后端?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何判斷當前請求是針對后端頁面還是前端頁面?此檢查將在觀察者內部完成,因此如果有幫助,我確實可以訪問請求對象.

How can I tell if the current request is for a backend or frontend page? This check will be done inside an observer, so I do have access to the request object if that helps.

我考慮過檢查 Mage::getSingleton('admin/session')->getUser() 但我認為這不是一個非常可靠的方法.我希望有更好的解決方案.

I considered checking Mage::getSingleton('admin/session')->getUser() but I don't think that's a very reliable method. I'm hoping for a better solution.

推薦答案

這是沒有好的答案的領域之一.Magento 本身并沒有為此信息提供明確的方法/API,因此對于任何解決方案,您都需要檢查環境并進行推斷.

This is one of those areas where there's no good answer. Magento itself doesn't provide an explicit method/API for this information, so with any solution you'll need to examine the environment and infer things.

我正在使用

Mage::app()->getStore()->isAdmin()

有一段時間了,但事實證明,某些管理頁面(Magento Connect 包管理器)并非如此.出于某種原因,此頁面將商店 ID 顯式設置為 1,這使得 isAdmin 返回為 false.

for a while, but it turns out there are certain admin pages (the Magento Connect Package manager) where this isn't true. For some reason this page explicitly sets the store id to be 1, which makes isAdmin return as false.

#File: app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php
public function indexAction()
{
    $this->_title($this->__('System'))
         ->_title($this->__('Magento Connect'))
         ->_title($this->__('Package Extensions'));

    Mage::app()->getStore()->setStoreId(1);
    $this->_forward('edit');
}

可能還有其他頁面有這種行為,

There may be other pages with this behavior,

另一個好辦法是檢查設計包的區域"屬性.

Another good bet is to check the "area" property of the design package.

對于管理中的頁面,這似乎不太可能被覆蓋,因為該區域會影響管理區域設計模板和布局 XML 文件的路徑.

This seems less likely to be overridden for a page that's in the admin, since the area impacts the path to the admin areas design templates and layout XML files.

無論您選擇從環境中推斷出什么,創建新的 Magento 模塊,并為其添加幫助類

Regardless of what you choose to infer from the environment, create new Magento module, and add a helper class to it

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

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

        return false;
    }
}

然后每當您需要檢查您是否在管理員中時,請使用此助手

and then whenever you need to check if you're in the admin, use this helper

if( Mage::helper('modulename/isadmin')->isAdmin() )
{
    //do the thing about the admin thing
}

這樣,當/如果您發現管理檢查邏輯中的漏洞,您可以在一個集中的地方更正所有內容.

This way, when/if you discover holes in your admin checking logic, you can correct everything in one centralized place.

這篇關于Magento 請求 - 前端還是后端?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 日本三级电影在线观看视频 | 超碰520 | 午夜av电影| 日本韩国欧美在线观看 | 九九久久99 | 日韩午夜影院 | 欧美bondage紧缚视频 | 国产精品视频一区二区三区 | 欧美电影网 | 男人天堂av网站 | 中国91av| 亚洲成人免费视频在线 | 狠狠做六月爱婷婷综合aⅴ 国产精品视频网 | 日韩视频中文字幕 | 日本大香伊一区二区三区 | 国产97在线看| 亚洲午夜在线 | 精品国产黄色片 | 国产精品精品视频一区二区三区 | aaa级片| 国产日韩精品一区 | 亚洲精品久久区二区三区蜜桃臀 | 日韩一二三区 | 国产一区二区黑人欧美xxxx | 国产色婷婷精品综合在线手机播放 | 福利视频一区 | 欧美久久一区二区 | 久久一区二区三区四区 | 亚洲精品日韩一区二区电影 | 国产精品a一区二区三区网址 | 久草青青 | 人妖无码| 91精品久久久久久久久久 | 亚洲成人精选 | 久久免费视频网 | 欧美日韩一卡二卡 | 免费一区 | 欧美日韩不卡合集视频 | 久热国产精品 | 天天视频一区二区三区 | 人人草天天草 |