【问题标题】:Magento - overriding Adminhtml blockMagento - 覆盖 Adminhtml 块
【发布时间】:2009-12-09 21:09:09
【问题描述】:

我花了几个小时试图覆盖扩展中“添加商店”和“编辑商店”页面的 Magento 块,以向其中添加另一个文本框。在翻阅书籍和谷歌搜索后,我发现了一些人们说有效的解决方案,但不适合我。

一个推荐是this one

我从 Lee Saferite 那里复制了所谓的正确解决方案,该解决方案适用于原始海报,但不适用于我。当然,我将值更改为我要覆盖的类和新修改的类。

我的 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>

还有位于 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()
    { ... }
}

此类包含新的输入字段。如果我在以下位置修改原始核心文件,这些字段会完美显示:

app/core/Mage/Adminhtml/Block/System/Store/Edit.php

但我真的希望我的扩展程序覆盖它。如有必要,我可以发布我的整个 config.xml,但它主要是创建顶级管理菜单并指定扩展信息,仅此而已。

对出了什么问题有任何想法吗?非常感谢您的解决方案!

【问题讨论】:

    标签: php magento overriding


    【解决方案1】:

    如下所示,稍作修改。您似乎将“edit”拼错为“sdit”。

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

    另外请记住,如果您想使用 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>
    

    【讨论】:

      【解决方案2】:

      在阅读了几个线程后,我找到了解决覆盖Mage_Adminhtml_Block_Widget_Grid 的问题。

      正如thread中提到的那样@
      "您只能在配置中覆盖(重写)被实例化的块。您不能将任何东西注入到类层次结构中,因为 PHP 不支持它"

      我想重写方法protected function _addColumnFilterToCollection($column)

      对于Mage_Adminhtml_Block_Sales_Order_Grid的扩展层次结构。

      我没有覆盖Mage_Adminhtml_Block_Widget_Grid,而是覆盖了Mage_Adminhtml_Block_Sales_Order_Grid类并将我的函数放在那里。

      对我来说这很好用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-03
        • 2015-04-18
        • 1970-01-01
        • 2015-09-09
        • 2015-08-29
        • 2012-07-06
        相关资源
        最近更新 更多