Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

php - 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. 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. Of course, I changed the values to the class I'm overriding and the new modified class.

My config.xml (the relevant part):

<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:

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

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.

Any ideas on what goes wrong? A solution would be HIGHLY appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Shown below, with a slight modification. It appears that you've misspelt "edit" as "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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...