久久久久久久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)題以包含屬性)
主站蜘蛛池模板: 夜夜操天天操 | 亚洲精品久久久久久久久久久 | 精品无人国产偷自产在线 | 99久久精品一区二区成人 | av大片在线观看 | 欧美精品黄色 | 日韩精品在线播放 | 天天爽爽 | 激情高潮到大叫狂喷水 | 一区二区三区久久 | 国产逼逼 | 人人看人人干 | 一区不卡| 亚洲精品自拍视频 | 四级黄色片 | 久久久久久综合 | 91在线精品秘密一区二区 | 国产九九精品 | 久久精品视频网 | 超碰人人干| jlzzjlzz欧美大全 | 午夜理伦三级理论 | 欧美精品日韩少妇 | 中文字幕自拍偷拍 | 免费黄色一级视频 | 免费国产网站 | 日韩激情久久 | 黄色片在线免费观看 | 在线欧美 | 欧美综合色 | 中文字幕在线观看一区二区三区 | 黄色大片网站 | 奇米av | 天天干天天看 | 日韩欧美在线看 | 人人爽人人爽人人片av | 99re国产 | 中文字幕在线观看第一页 | 高潮毛片又色又爽免费 | 久草视频观看 | 一级大片 |