2011-08-03 9 views
6

私は私が既にバックエンドadminhtmlにモジュールを存在していた私は実装されているこのガイドCustom Module with Custom Database TableMagentoのadminhtmlカスタムモジュールには、グリッドを見せて二回

以下でMagentoのために新しいです。私はデータベースからのものを取って、adminhtmlページには何も書いていません。 adminhtmlでグリッドを2回取得している以外は、すべて正常に動作します。私は同じグリッドを2回取得しています。私は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())); 
}} 

のthatsと、この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')); 

私はそれを2回読み込んでいます。

+2

他の人が見つけやすいように、おそらくこの回答を受け入れるべきです。 –

6

たぶん、あなたはレイアウトに挿入するしている、

adminhtml>デフォルト>デフォルト>レイアウトでpricenotify.xmlをご確認ください。

ような:

<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'タグ内に読み込まれていてグリッドが2回表示されています。ですから、グリッドページに既に存在する可能性があるGrid.phpの 'id'を設定している間は、一般的な名前は付けません。

0

私の場合は、編集/フォームで起こっていて、私はAdminhtmlコントローラで意図せずにrenderLayout()を複製していました。

$this->renderLayout(); 
関連する問題