简体   繁体   中英

magento rewrite not working

I created a module that used a custom widget/grid/column for my admin grid to display a thumbnail image and everything worked. Now I need to create another module in the same project that does the same thing, but the image column will not work. It appears like its not even loading my new class, since it won't execute any stmt I put into the file. I know its properly loading data, b/c if I change the type to text, then the correct info from the DB is populated into the field. But when I change to my new 'image' type the cell is empty. does anyone know why it wouldn't be working?

ABT/Background/etc/config.xml << doesn't work

<global>
    ....
    <blocks>
        <background>
            <class>ABT_Background_Block</class>
        </background>
        <adminhtml>
            <rewrite>
                <widget_grid_column>ABT_Background_Block_Widget_Grid_Column</widget_grid_column>
            </rewrite>
        </adminhtml>
    </blocks>
    ....
</global>

the module I copied to get me up and running has the exact same config setup, but yet it works fine ABT/Feature/etc/config.xml << this works correctly

<global>
    ....
    <blocks>
        <feature>
            <class>ABT_Feature_Block</class>
        </feature>
        <adminhtml>
            <rewrite>
                <widget_grid_column>ABT_Feature_Block_Widget_Grid_Column</widget_grid_column>   
            </rewrite>
        </adminhtml>
    </blocks>
    ....
</global>

Here's what happening with Magento when you rewrite a class.

When Magento instantiates a Block class, it uses code something like the following

$this->getLayout()->createBlock('adminhtml/widget_grid_column')

The createBlock method is a factory. Magento uses the identifier

adminhtml/widget_grid_column

to lookup which class should be instantiated. By default, that's

Mage_Adminhtml_Block_Widget_Grid_Column

When you create your rewrite, you're telling Magento

Hey. instead of using 'Mage_Adminhtml_Block_Widget_Grid_Column' for a 'adminhtml/widget_grid_column', you should use 'ABT_Background_Block_Widget_Grid_Column'

This means that, for any given system, a class may only be rewritten once . In the code you're showing above, you're trying to rewrite the class twice. Only one of your rewrites will win.

The quick approach I'd take is to keep all your customizations in a single override class.

More generally, I try to avoid using rewrites if at all possible. They're a powerful system, but should be using sparingly. I haven't done much grid customizing, but the general approach I'd try to take would be to change the adminhtml layout to instantiate a new grid class from my custom module that extends an existing grid class, which in turn may use custom column classes.

More work up front, but once you've figured it out you can use the technique over and over again, and not worry abou conflicts from a rewrite.

I'm not sure to have got your setup correctly.

Anyway, it looks like you have two override rules on the same class Widget_Grid_Column . The last module loaded is the ABT_Feature so the rule of that block overwrite the rule of the ABT_Background module.

You have two solutions:

  1. merge the Feature and Background module in a single one
  2. make the Feature block depending on the Background one and update the rewrite rule so that the ABT_Feature_Block_Widget_Grid_Column class will extend the ABT_Background_Block_Widget_Grid_Column .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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