2011-08-03 39 views
6

我是新本指南Custom Module with Custom Database TableMagento的adminhtml自定义模块它显示网格两次

我已经实现了我的已经存在模块到后端adminhtml以下到Magento的。我正在从数据库中取出东西,并在adminhtml页面上浏览。一切工作正常,除非我在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(); 
    } 
+0

发现网格容器或更新您的问题与网格容器和layout.xml。 – azakolyukin

回答

1

确保网格块尚未装入相应的布局.xml文件。

3

我修好了。我只需要注释掉

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

from indexAction我想我会加载它两次。

+2

你可能应该接受这个答案,让其他人更容易找到。 –

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> 

删除此块或注释,你添加的内容就行了。

0

嗯,我面临同样的问题,但在我的情况下,这是由于$this->setId('messages');行(在你的Grid.php结构中)。由于magento在其网格页面(用于显示通知)中已经具有相同的<div id="messages"></div>,因此我的网格内容已在此“div”标签中加载,因此显示网格两次。所以吸取的教训是不要在Grid.php中设置'id'时给出通用名称,这可能已经出现在网格页面中。

0

在我的情况下,它发生在编辑/表单上,并且我无意中在我的Adminhtml控制器上复制了renderLayout()。

$this->renderLayout(); 
相关问题