简体   繁体   English

Magento - 覆盖Adminhtml块

[英]Magento - overriding Adminhtml block

I've spent hours trying to override the Magento block for the "Add store" and "Edit store" pages in an extension, to add another text box to it. 我花了好几个小时试图覆盖扩展中“添加商店”和“编辑商店”页面的Magento块,以便为其添加另一个文本框。 After Going through books and Googling, I've found several solutions which people say are working, however not for me. 经过书籍和谷歌搜索后,我发现了一些人们认为有效的解决方案,但不适合我。

One recommendation was this one . 一个建议就是这个

I've copied the supposedly correct solution from Lee Saferite which works for the original poster but not for me. 我复制了Lee Saferite所谓的正确解决方案,该解决方案适用于原始海报但不适用于我。 Of course, I changed the values to the class I'm overriding and the new modified class. 当然,我将值更改为我重写的类和新修改的类。

My config.xml (the relevant part): 我的config.xml(相关部分):

<global>
    <blocks>
      <adminhtml>
        <rewrite>
          <system_store_sdit_form>Nintera_General_Block_StoreEdit</system_store_sdit_form>
        </rewrite>
      </adminhtml>
    </blocks>
    <resources></resources>
    <helpers>
      <Nintera_General>
        <class>Nintera_General_Helper</class>
      </Nintera_General>
    </helpers>
  </global>

And the block class located at Nintera/General/Block/StoreEdit.php: 块类位于Nintera / General / Block / StoreEdit.php:

class Nintera_General_Block_StoreEdit extends Mage_Adminhtml_Block_System_Store_Edit_Form
{
    /**
     * Prepare form data
     *
     * return Mage_Adminhtml_Block_Widget_Form
     */
    protected function _prepareForm()
    { ... }
}

This class contains new input fields. 该类包含新的输入字段。 The fields show up perfectly if I modify the original core file at: 如果我在以下位置修改原始核心文件,则字段会完美显示:

app/core/Mage/Adminhtml/Block/System/Store/Edit.php 应用程序/核心/法师/ Adminhtml /模块/系统/存储/ Edit.php

But I really want my extension to override it. 但我真的希望我的扩展能够覆盖它。 If necessary I can post my entire config.xml but it's mostly creating a top level admin menu and specifies extension info, not much else. 如果有必要,我可以发布我的整个config.xml,但它主要创建一个顶级管理菜单,并指定扩展信息,而不是其他。

Any ideas on what goes wrong? 什么出错的想法? A solution would be HIGHLY appreciated! 一个解决方案将非常感谢!

Shown below, with a slight modification. 如下图所示,稍作修改。 It appears that you've misspelt "edit" as "sdit". 看来你拼错了“编辑”为“sdit”。

<global>
   <blocks>
      <adminhtml>
        <rewrite>
          <system_store_edit_form>Nintera_General_Block_StoreEdit</system_store_edit_form>
        </rewrite>
      </adminhtml>
   </blocks>
</global>

Also keep in mind that if you want to call other blocks using the Mage::getModel("nintera_general/myblock") syntax, you'll need to add your own blocks to that code as well, as shown below. 另外请记住,如果要使用Mage :: getModel(“nintera_general / myblock”)语法调用其他块,则还需要将自己的块添加到该代码中,如下所示。

<global>
   <blocks>
      <adminhtml>
        <rewrite>
          <system_store_edit_form>Nintera_General_Block_StoreEdit</system_store_edit_form>
        </rewrite>
      </adminhtml>
      <nintera_general>
         <class>Nintera_General_Block</class>
      </nintera_general>
   </blocks>
</global>

After Reading several threads I've found the solution for this issue of overriding Mage_Adminhtml_Block_Widget_Grid . 阅读几个线程之后,我找到了覆盖Mage_Adminhtml_Block_Widget_Grid问题的解决方案。

As mentioned in this thread 正如本帖所述
" You can override (rewrite) in config only the blocks that are instantiated. You cannot inject anything into classes hierarchy as it is not supported by PHP " 您可以在配置中仅覆盖(重写)实例化的块。您不能将任何内容注入到类层次结构中,因为PHP不支持它

I wanted to override the method protected function _addColumnFilterToCollection($column) 我想覆盖方法protected function _addColumnFilterToCollection($column)

for the extended hierarchy of Mage_Adminhtml_Block_Sales_Order_Grid . 用于Mage_Adminhtml_Block_Sales_Order_Grid的扩展层次结构。

Instead of overriding Mage_Adminhtml_Block_Widget_Grid I override the class Mage_Adminhtml_Block_Sales_Order_Grid and place my function there. 我重写了Mage_Adminhtml_Block_Sales_Order_Grid类,而不是重写Mage_Adminhtml_Block_Widget_Grid ,并将我的函数放在那里。

And for me this works fine. 对我来说这很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM