magento 重写不起作用

发布于 2024-10-04 04:16:00 字数 1264 浏览 0 评论 0原文

我创建了一个模块,该模块使用自定义小部件/网格/列作为我的管理网格来显示缩略图,并且一切正常。现在我需要在同一项目中创建另一个模块来执行相同的操作,但图像列将不起作用。看起来它甚至没有加载我的新类,因为它不会执行我放入文件中的任何 stmt。我知道它正确加载数据,b/c 如果我将类型更改为文本,那么数据库中的正确信息将填充到该字段中。但是当我更改为新的“图像”类型时,单元格为空。有谁知道为什么它不起作用?

ABT/Background/etc/config.xml <<不起作用

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

我复制来启动和运行的模块具有完全相同的配置设置,但它工作正常 ABT/Feature/etc/config.xml <<这工作正常

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思念绕指尖 2024-10-11 04:16:01

我不确定您的设置是否正确。

不管怎样,看起来你在同一个类 Widget_Grid_Column 上有两个覆盖规则。最后加载的模块是 ABT_Feature,因此该块的规则会覆盖 ABT_Background 模块的规则。

您有两种解决方案:

  1. 将功能模块和背景模块合并为一个模块,
  2. 使功能模块依赖于背景模块,并更新重写规则,以便 ABT_Feature_Block_Widget_Grid_Column 类扩展 ABT_Background_Block_Widget_Grid_Column代码>.

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.
看春风乍起 2024-10-11 04:16:00

以下是当您重写类时 Magento 会发生的情况。

当 Magento 实例化一个 Block 类时,它使用类似以下的代码

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

createBlock 方法是一个工厂。 Magento 使用标识符

adminhtml/widget_grid_column

来查找应该实例化哪个类。默认情况下,

Mage_Adminhtml_Block_Widget_Grid_Column

当您创建重写时,您是在告诉 Magento

嘿。您应该使用“ABT_Background_Block_Widget_Grid_Column”,而不是对“adminhtml/widget_grid_column”使用“Mage_Adminhtml_Block_Widget_Grid_Column”

这意味着,对于任何给定系统,类只能重写一次。在上面显示的代码中,您尝试重写该类两次。只有您的重写之一会获胜。

我采取的快速方法是将您的所有自定义保留在单个覆盖类中。

更一般地说,如果可能的话,我会尽量避免使用重写。它们是一个强大的系统,但应谨慎使用。我没有做过太多的网格定制,但我尝试采取的一般方法是更改​​ adminhtml 布局以从我的自定义模块实例化一个新的网格类,该模块扩展现有的网格类,这反过来又可以使用自定义列类。

前期需要做更多的工作,但是一旦你弄清楚了,你就可以一遍又一遍地使用该技术,而不必担心重写带来的冲突。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文