6

我是 magento 的新手,遵循本指南Custom Module with Custom Database Table

我已经将我已经存在的模块实现到后端 adminhtml。我正在从数据库中获取东西并在 adminhtml 页面上显示 ot。一切正常,除了我在 adminhtml 上获得了两次网格。我两次得到相同的网格。我已经看了 2 个小时的代码无法弄清楚。如果有人知道如何解决这个问题,我将非常感谢。干杯

这就是我 grid.php 中的代码

<?php

      class Ecom_Pricenotify_Block_Adminhtml_Pricenotify_Grid extends Mage_Adminhtml_Block_Widget_Grid{
public function __construct()
{
    parent::__construct();
    $this->setId('pricenotifyGrid');
    // This is the primary key of the database
    $this->setDefaultSort('pricenotify_id');
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
}

protected function _prepareCollection()
{
    $collection = Mage::getModel('pricenotify/pricenotify')->getCollection();
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

protected function _prepareColumns()
{
    $this->addColumn('pricenotify_id', array(
        'header'    => Mage::helper('pricenotify')->__('Notification ID'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'pricenotify_id',
    ));

    $this->addColumn('prod_id', array(
        'header'    => Mage::helper('pricenotify')->__('Product ID'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'prod_id',
    ));


    $this->addColumn('prod_price', array(
        'header'    => Mage::helper('pricenotify')->__('Product Price'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'prod_price',
    ));

    $this->addColumn('user_price', array(
        'header'    => Mage::helper('pricenotify')->__('User Price'),
        'align'     =>'left',
        'width'     => '50px',
        'index'     => 'user_price',
    ));

    $this->addColumn('email', array(
        'header'    => Mage::helper('pricenotify')->__('E-Mail Address'),
        'align'     =>'left',
        'width'     => '150px',
        'index'     => 'email',
    ));

    $this->addColumn('created_time', array(
        'header'    => Mage::helper('pricenotify')->__('Creation Time'),
        'align'     => 'left',
        'width'     => '120px',
        'type'      => 'date',
        'default'   => '--',
        'index'     => 'created_time',
    ));


    $this->addColumn('status', array(

        'header'    => Mage::helper('pricenotify')->__('Status'),
        'align'     => 'left',
        'width'     => '80px',
        'index'     => 'status',
        'type'      => 'options',
        'options'   => array(
            'success' => 'Inactive',
            'pending' => 'Active',
        ),
    ));

   return parent::_prepareColumns();
}

public function getRowUrl($row)
{
   return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}}

这个 indexAction 函数来自控制器

  public function indexAction() {
    $this->_initAction();       
    $this->_addContent($this->getLayout()->createBlock('pricenotify/adminhtml_pricenotify'));
    $this->renderLayout();
  }
4

5 回答 5

6

也许你将它插入到布局中,检查 pricenotify.xml

adminhtml>默认>默认>布局。

如:

  <pricenotify_adminhtml_manager_pricenotify>
        <block type="core/text_list" name="root" output="toHtml">
            <block type="pricenotify/adminhtml_pricenotify_grid" name="pricenotify.grid"/>
        </block>
  </pricenotify_adminhtml_manager_pricenotify>

删除此块或注释您添加内容的行。

于 2012-10-08T13:37:45.090 回答
4

I fixed it. i only had to comment out

//$this->_addContent($this->getLayout()->createBlock('pricenotify/adminhtml_pricenotify'));

from indexAction i guess iwas loading it twice.

于 2011-08-04T06:23:10.203 回答
2

确保网格块尚未加载到相应的 layout.xml 文件中。

于 2011-08-03T15:09:34.427 回答
0

就我而言,它发生在 Edit/Form 上,并且我无意中在我的 Adminhtml 控制器上复制了 renderLayout()。

$this->renderLayout();
于 2016-03-01T00:55:31.800 回答
0

好吧,我遇到了同样的问题,但就我而言,这是由于$this->setId('messages');行(在您的 Grid.php 构造中)。因为 magento 在它的网格页面(用于显示通知)中已经有相同<div id="messages"></div>的内容,因此我的网格内容被加载到这个 'div' 标签中,因此显示了两次网格。因此,吸取的教训是在 Grid.php 中设置您的“id”时不要给出通用名称,这可能已经存在于网格页面中。

于 2015-10-13T08:53:38.613 回答