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

Magento - 擴(kuò)展相同核心類的多個(gè)類

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

問題描述

我相信我們都遇到過這樣的情況:您有多個(gè)擴(kuò)展,其中一個(gè)塊或模型重寫了相同的核心塊/模型.我遇到的問題是:你如何控制 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?

例如,假設(shè)我們有 2 個(gè)擴(kuò)展,包含以下 2 個(gè)類:

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級(jí)

<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 {}

--

推薦的解決方案是更改其中一個(gè),以便它們擴(kuò)展另一個(gè)并將它們鏈接在一起(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 不一定是這樣看的.我不知道它是按字母順序排列的還是有點(diǎn)隨機(jī)的,但有時(shí)這有效,有時(shí)則無效.在某些情況下,Magento 會(huì)優(yōu)先使用 ClassB,所有對(duì) createBlock('catalog/product_view') 的調(diào)用都會(huì)創(chuàng)建一個(gè) ClassB 的實(shí)例,完全繞過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.

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

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?

推薦答案

當(dāng) Magento 獲取用于特定塊的類時(shí),它會(huì)在合并的 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,將其與配置樹合并,然后加載另一個(gè)的方式,只能存在一個(gè)節(jié)點(diǎn)> 模型.這意味著您只能將一個(gè)類別名解析為一個(gè)類名.

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

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

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.

這篇關(guān)于Magento - 擴(kuò)展相同核心類的多個(gè)類的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Override Magento Config(覆蓋 Magento 配置)
What would cause a print_r and/or a var_dump to fail debugging a variable?(什么會(huì)導(dǎo)致 print_r 和/或 var_dump 調(diào)試變量失敗?)
How to update custom options programatically in magento?(如何在 magento 中以編程方式更新自定義選項(xiàng)?)
Magento 404 on Admin Page(管理頁面上的 Magento 404)
Magento - get price rules from order(Magento - 從訂單中獲取價(jià)格規(guī)則)
Magento Change Product Page Titles to Include Attributes(Magento 更改產(chǎn)品頁面標(biāo)題以包含屬性)
主站蜘蛛池模板: 日韩视频精品在线 | 亚洲精品乱码久久久久v最新版 | 亚洲成人蜜桃 | 欧美成人精品一区二区男人看 | 91文字幕巨乱亚洲香蕉 | 欧美精品片 | 一区二区在线 | 午夜精品福利视频 | 日韩欧美中文在线 | 操到爽| 性欧美精品一区二区三区在线播放 | 亚洲成网| 古典武侠第一页久久777 | 亚洲高清视频一区二区 | 久久se精品一区精品二区 | 久久精品视频91 | 一区二区在线视频 | 欧美精品v国产精品v日韩精品 | 国产精品久久久久久婷婷天堂 | 免费成人在线网站 | 国产精品视频999 | 自拍视频国产 | 国产电影一区 | 成人蜜桃av | 国产 亚洲 网红 主播 | 中文字幕免费在线 | 亚洲国产精品一区二区三区 | 久久精品国产亚洲 | 欧美日韩在线免费观看 | 日本久久精品视频 | 亚洲一区二区三区免费在线观看 | 二区在线视频 | 亚洲精品中文字幕 | www.日日操 | 亚洲午夜精品久久久久久app | 亚洲成人一区二区 | 欧美精品一区在线 | 亚洲日韩视频 | 在线区| 午夜影院 | 久久高清|