magento更改adminhtml网格页面中显示的默认数字行

时间:2011-02-26 05:41:21

标签: magento observer-pattern

我想将admin中显示的默认行数设置为高于20 我在http://inchoo.net/ecommerce/magento/magento-admin-grid-how-to-change-number-of-rows/跟进,但我正在尝试制作一个模块来完成任务。 Magento版本是1.4.2.0。

我得到的错误是Mage registry key "_singleton/grid/observer" already exists

我在app/code/local/Company/Custom/etc/config.xml

<config>
  <adminhtml>
    <events>
      <core_block_abstract_prepare_layout_before>
        <observers>
          <grid_observer>
            <class>grid/observer</class>
            <method>applyLimitToGrid</method>
          </grid_observer>
        </observers>
      </core_block_abstract_prepare_layout_before>
    </events>
  </adminhtml>
</config>

app/code/local/Company/Custom/Model/Observer.php

class Company_Custom_Grid_Model_Observer
{
    public function applyLimitToGrid(Varien_Event_Observer $observer)
    {
        $block = $observer->getEvent()->getBlock();
        if (($block instanceof Mage_Adminhtml_Block_Widget_Grid) && !($block  instanceof Mage_Adminhtml_Block_Dashboard_Grid)) {
            $block->setDefaultLimit(200);
        }
    }
}

app/etc/modules/Company_Custom.xml

<config>
  <modules>
    <Company_Custom>
      <codePool>local</codePool>
      <active>true</active>
    </Company_Custom>
  </modules>
</config>

3 个答案:

答案 0 :(得分:1)

class Company_Custom_Grid_Model_Observer

应该是

class Company_Custom_Model_Observer

答案 1 :(得分:0)

您没有模块模型类声明:

<global>
  <models>
    <modulename>
      <class>Namespace_ModuleName_Model</class>
    </modulename>
  </models>
</global>

答案 2 :(得分:0)

最大的变化发生在Company/Custom/etc/config.xml,我将<events>部分放在<global>块中,而不是<adminhtml>

同样在该文件中,修复错误消息为<class>Company_Custom_Model_Observer</class>(之前我有grid/observer ...)