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

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

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

問題描述

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

--

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

所以我的問題是:當(dāng) 2 個不同的擴(kuò)展都重寫核心 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?

推薦答案

當(dāng) 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,將其與配置樹合并,然后加載另一個的方式,只能存在一個節(jié)點> 模型.這意味著您只能將一個類別名解析為一個類名.

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)簽.這個標(biāo)簽允許你說某些模塊依賴在另一個模塊上,這意味著它們的config.xml將在另一個模塊的config.xml之后加載.通過這種方式,您可以控制模塊加載的順序,從而控制哪個合并的重寫節(jié)點獲勝",這反過來又會讓您知道哪個類需要成為繼承鏈中的最后一個.

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ò)展相同核心類的多個類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Override Magento Config(覆蓋 Magento 配置)
What would cause a print_r and/or a var_dump to fail debugging a variable?(什么會導(dǎo)致 print_r 和/或 var_dump 調(diào)試變量失敗?)
How to update custom options programatically in magento?(如何在 magento 中以編程方式更新自定義選項?)
Magento 404 on Admin Page(管理頁面上的 Magento 404)
Magento - get price rules from order(Magento - 從訂單中獲取價格規(guī)則)
Magento Change Product Page Titles to Include Attributes(Magento 更改產(chǎn)品頁面標(biāo)題以包含屬性)
主站蜘蛛池模板: 欧美日韩亚洲视频 | 国产中文一区二区三区 | 一区二区高清 | 色婷婷一区二区三区四区 | 在线欧美视频 | 日日骚网| 成人免费视频一区二区 | 91国内精精品久久久久久婷婷 | 久久99精品国产自在现线小黄鸭 | 情侣av| 98成人网| 色吧综合网 | 欧美日韩在线观看一区 | 一区视频| h视频在线观看免费 | 亚洲精品一区国产精品 | av在线成人 | 亚洲国产成人一区二区 | 狠狠躁天天躁夜夜躁婷婷老牛影视 | 91视频www.| 综合国产 | www.99热| 全部免费毛片在线播放网站 | 特级毛片www | 在线观看成人小视频 | www.亚洲一区二区 | 久在线观看 | 日韩国产免费观看 | 成人免费黄色片 | 日本天天操 | 青青操av| av天天操 | 久久精品一区 | 国产91av视频在线观看 | 欧美精品一二区 | 91精品国产91久久久久久最新 | 日韩欧美精品一区 | 亚洲国产精品日韩av不卡在线 | 日本国产高清 | 日韩精品一区在线观看 | 精品国产一区二区三区免费 |