久久久久久久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)
主站蜘蛛池模板: 精品国产欧美一区二区 | 91国产在线视频在线 | 人人看人人射 | 久草视频网站 | 亚洲一区二区在线视频 | 人人艹人人 | 粉嫩一区二区三区性色av | 亚洲xx在线| 亚洲精品字幕 | 日韩成人免费视频 | av看看 | 国产精彩视频在线观看 | 国产欧美一级二级三级在线视频 | 亚洲欧美在线视频 | 久久久久网站 | h视频免费在线观看 | www.日韩 | 黄色精品| 亚洲视频欧美视频 | 欧美区日韩区 | 北条麻妃99精品青青久久主播 | 国产色婷婷久久99精品91 | 色婷婷av一区二区三区软件 | 国产 欧美 日韩 一区 | 男女国产视频 | www.国产| 国产精品日韩一区二区 | 亚洲区一区二 | 夫妻午夜影院 | 亚洲综合五月天婷婷 | 久久香焦 | 亚洲精品99 | 精品福利视频一区二区三区 | 国产亚洲精品久久情网 | 国产在线观看不卡一区二区三区 | av黄色在线 | 国产成人一区二区 | 欧美色a v | 四色永久| 做a的各种视频 | 一区中文字幕 |