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

Magento - 擴展相同核心類的多個類

Magento - multiple classes extending same core class(Magento - 擴展相同核心類的多個類)
本文介紹了Magento - 擴展相同核心類的多個類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我相信我們都遇到過這樣的情況:您有多個擴展,其中一個塊或模型重寫了相同的核心塊/模型.我遇到的問題是:你如何控制 Magento 看到這些類的順序?

I'm sure we've all run into a situation where you have multiple extensions with a block or model that rewrites the same core block/model. The problem I've run into is this: How do you control the order in which Magento sees these classes?

例如,假設我們有 2 個擴展,包含以下 2 個類:

For example, let's say we have 2 extensions with the following 2 classes:

config.xml

<catalog>
    <rewrite>
        <product_view>My_ClassA_Block_Catalog_Product_View</product_view>
    </rewrite>
</catalog>

My/ClassA/Block/Catalog/Product/View.php

class My_ClassA_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View {}

B級

<catalog>
    <rewrite>
        <product_view>My_ClassB_Block_Catalog_Product_View</product_view>
    </rewrite>
</catalog>

My/ClassB/Block/Catalog/Product/View.php

class My_ClassB_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View {}

--

推薦的解決方案是更改其中一個,以便它們擴展另一個并將它們鏈接在一起(class A extends B {}class B extends C {},等):

My/ClassA/Block/Catalog/Product/View.php

class My_ClassA_Block_Catalog_Product_View extends My_ClassB_Block_Catalog_Product_View {}

My/ClassB/Block/Catalog/Product/View.php

class My_ClassB_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View {}

--

我遇到的問題是 Magento 不一定是這樣看的.我不知道它是按字母順序排列的還是有點隨機的,但有時這有效,有時則無效.在某些情況下,Magento 會優先使用 ClassB,所有對 createBlock('catalog/product_view') 的調用都會創建一個 ClassB 的實例,完全繞過ClassA 中的任何代碼.

--

The problem I've run into is that Magento doesn't necessarily see it that way. I don't know if it's alphabetical or somewhat random, but sometimes this works and sometimes it doesn't. In some cases, Magento gives priority to ClassB and all calls to createBlock('catalog/product_view') create an instance of ClassB, completely bypassing any code in ClassA.

所以我的問題是:當 2 個不同的擴展都重寫核心 catalog_product_view 類時,我如何控制 createBlock('catalog/product_view') 實例化哪個類?

So my question is this: How do I control which class gets instantiated by createBlock('catalog/product_view') when 2 different extensions both rewrite the core catalog_product_view class?

推薦答案

當 Magento 獲取用于特定塊的類時,它會在合并的 config.xml 樹中查找

When Magento fetches the class to use for a particular block, it looks inside the merged config.xml tree for a single node at

catalog/rewrite/product_view

多次重寫的問題是,由于 Magento 加載模塊的 XML,將其與配置樹合并,然后加載另一個的方式,只能存在一個節點> 模型.這意味著您只能將一個類別名解析為一個類名.

The problem with multiple rewrites is, only one node can be there due to the way Magento loads a module's XML, merges it with the config tree, and then loads another model. This means you can only ever have one class alias resolve to one class name.

那是

app/etc/modules/*.xml

發揮作用.這些文件告訴 Magento 使用哪些模塊.它們還支持 標簽.這個標簽允許你說某些模塊依賴在另一個模塊上,這意味著它們的config.xml將在另一個模塊的config.xml之后加載.通過這種方式,您可以控制模塊加載的順序,從而控制哪個合并的重寫節點獲勝",這反過來又會讓您知道哪個類需要成為繼承鏈中的最后一個.

come into play. These files tell Magento which modules to use. They also have support for a <depends> tag. This tag allows you to say certain modules depend on another module, which means their config.xml will be loaded after another module's config.xml. In this way, you can control which order the modules are loaded in, and therefore control which merged rewrite node "wins", which in turn will allow you to know which class needs to be the final in your inheritance chain.

這篇關于Magento - 擴展相同核心類的多個類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Override Magento Config(覆蓋 Magento 配置)
What would cause a print_r and/or a var_dump to fail debugging a variable?(什么會導致 print_r 和/或 var_dump 調試變量失敗?)
How to update custom options programatically in magento?(如何在 magento 中以編程方式更新自定義選項?)
Magento 404 on Admin Page(管理頁面上的 Magento 404)
Magento - get price rules from order(Magento - 從訂單中獲取價格規則)
Magento Change Product Page Titles to Include Attributes(Magento 更改產品頁面標題以包含屬性)
主站蜘蛛池模板: 91视频网址 | 久久精品小短片 | 久久久婷婷 | 亚洲成人免费网址 | 国产精品久久久久久久久久久久久 | 国产精品视频久久久久 | wwwxx在线观看| 巨大荫蒂视频欧美另类大 | 精品91久久 | 日本小电影网站 | 久久精品欧美一区二区三区麻豆 | av一区在线| 婷婷开心激情综合五月天 | 中国一级特黄视频 | 久久久国产精品视频 | 精品中文字幕在线观看 | 97精品久久 | 成年人在线视频 | 天天干天天爱天天爽 | 天天干天天色 | 欧美黑人体内she精在线观看 | 一级黄色片一级黄色片 | 三级特黄特色视频 | 久久国产欧美日韩精品 | 国产精品毛片无码 | 国产毛片久久久久久久久春天 | 国产成人精品一区二区三区四区 | 精品国产一区二区三区性色av | 久久久99国产精品免费 | 天天色图| 中文字幕在线观看av | 在线观看国产视频 | 日韩高清成人 | 免费的一级视频 | 国产精品美女久久久 | 91精品国产乱码久久久久久久久 | 日韩电影一区 | 欧美一区精品 | 久久精品亚洲欧美日韩久久 | 亚洲成人免费观看 | 2018天天干天天操 |