0

到目前为止我所拥有的:

etc/modules/BugFix_MageAdminhtmlBlockWidgetGrid.xml

<?xml version="1.0"?>
<config>
    <modules>
        <BugFix_MageAdminhtmlBlockWidgetGrid>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Adminhtml />
            </depends>
        </BugFix_MageAdminhtmlBlockWidgetGrid>
    </modules>
</config>

app/local/BugFix/MageAdminhtmlBlockWidgetGrid/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <BugFix_MageAdminhtmlBlockWidgetGrid>
            <version>1.0.0</version>
        </BugFix_MageAdminhtmlBlockWidgetGrid>
    </modules>
    <global>
        <blocks>
            <mageadminhtmlblockwidgetgrid>
                <class>BugFix_MageAdminhtmlBlockWidgetGrid_Block</class>
            </mageadminhtmlblockwidgetgrid>
            <adminhtml>
                <rewrite>
                    <widget_grid>BugFix_MageAdminhtmlBlockWidgetGrid_Block_Widget_Grid</widget_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

app/local/BugFix/MageAdminhtmlBlockWidgetGrid/Block/Widget/Grid.php

<?php

class BugFix_MageAdminhtmlBlockWidgetGrid_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function getRowUrl($item)
    {
        $res = parent::getRowUrl($item);
        return ($res ? $res : '#');
    }
}

不知何故,上面的代码不起作用。应该是很简单的...

作为一个模块的错误修复适用于 Magento 1.4(并由 Magento 在 1.7 中修复)。

4

1 回答 1

0

子类化时重写不起作用。在这种情况下,grid classes subclass ( extends) 是 adminhtml grid 小部件,这意味着用于该类的名称是原始名称,而不是配置中的重写名称。

POC:

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);

include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();

$block = Mage::app()->getLayout()->createBlock('adminhtml/widget_grid');
echo get_class($block);
//or echo Mage::getConfig()->getBlockClassName('adminhtml/widget_grid');

$block = new Mage_Adminhtml_Block_Widget_Grid;
echo get_class($block);

In this case you will need to copy the path and file from the core codepool to the local codepool and change the definition in there. Because of the include path precedence the definition from the local codepool will be used. You must account for this in an upgrade, though.

于 2012-07-04T14:27:52.577 回答