Magento adminhtml custom module showing grid twice

I am new to magento following this tutorial User module with user database table

I have implemented my existing module in the backend adminhtml. I take material from the database and add it to the adminhtml page. Everything works fine, except that I get the grid twice in adminhtml. I get the same grid twice. I looked at the code, how 2 hours can not figure it out. if anyone knows how to fix this problem, I will be very cunning. greetings

this is the code from my 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())); }} 

and this index function acts from the controller

  public function indexAction() { $this->_initAction(); $this->_addContent($this->getLayout()->createBlock('pricenotify/adminhtml_pricenotify')); $this->renderLayout(); } 
+6
source share
5 answers

Perhaps you are pasting it into the layout, check pricenotify.xml in

adminhtml> default> default> location.

For instance:

  <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> 

Delete this block or comment on the line where you are adding content.

+6
source

I fixed it. I just had to comment

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

from indexAction, I think I downloaded it twice.

+3
source

make sure the grid block is not already loaded in the corresponding layout.xml file.

+1
source

Well, I ran into the same problem, but in my case it was due to the line $this->setId('messages'); (in your Grid.php construct). Since magento already has the <div id="messages"></div> on its grid page (for displaying notifications), which is why the contents of my grid are loaded inside this div tag, so the grid is displayed twice. So, the lesson learned does not give a common name when setting your "id" in Grid.php, which may already be present on the grid page.

0
source

In my case, this happened in Edit / Form, and I accidentally duplicated renderLayout () on my Adminhtml controller.

 $this->renderLayout(); 
0
source

Source: https://habr.com/ru/post/894194/


All Articles