我在Magento框架上工作。
我想重写Mage_Adminhtml_Block_Widget_Grid
来优化搜索过滤。
我在etc/config.xml
上添加了重写块,并将名称块添加为grid_search_date
。
<config>
<global>
<helpers>
<core>
<rewrite>
<data>Jdate_Format_Helper_Data</data>
</rewrite>
</core>
</helpers>
<blocks>
<grid_search_date>
<rewrite>
<widget_grid>Jdate_Format_Block_Widget_Grid</widget_grid>
</rewrite>
</grid_search_date>
<topmenu_admin_time>
<rewrite>
<widget_grid_column_renderer_date>Jdate_Format_Block_Widget_Grid_Column_Renderer_Date</widget_grid_column_renderer_date>
</rewrite>
</topmenu_admin_time>
</blocks>
</global>
</config>
你可以看到Jdate_Format_Block_Widget_Grid
想要重写widget_grid
,我们转到这个文件
class Jdate_Format_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
protected function _addColumnFilterToCollection($column)
{
if ($this->getCollection()) {
$field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex();
if ($column->getFilterConditionCallback()) {
call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
} else {
$cond = $column->getFilter()->getCondition();
die(var_dump($cond["orig_from"]));
die(var_dump($cond["orig_to"]));
if ($field && isset($cond)) {
$this->getCollection()->addFieldToFilter($field , $cond);
}
}
}
return $this;
}
}
但什么也没发生。但如果我直接将Widget_Grid
文件更改为这个,它就可以工作了。
知道吗?
尝试
<global>
<blocks>
<adminhtml> <!-- should be the name of the module -->
<rewrite>
<widget_grid>Jdate_Format_Block_Widget_Grid</widget_grid>
</rewrite>
</adminhtml>
</blocks>
.....