2011-08-03 38 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(); 
相關問題