magento adminhtml自定义模块it';它显示了两次网格
我不熟悉magento,只需遵循本指南即可 我已经将已经存在的模块实现到后端adminhtml。我正在从数据库中获取资料,并在adminhtml页面上浏览。一切正常,除了我在adminhtml上得到两次网格。我两次得到相同的网格。我已经看了2个小时的代码了,我想不出来。如果有人知道如何解决这个问题,我会大发雷霆。干杯 这是我的grid.php中的代码magento adminhtml自定义模块it';它显示了两次网格,magento,magento-1.4,magento-1.5,Magento,Magento 1.4,Magento 1.5,我不熟悉magento,只需遵循本指南即可 我已经将已经存在的模块实现到后端adminhtml。我正在从数据库中获取资料,并在adminhtml页面上浏览。一切正常,除了我在adminhtml上得到两次网格。我两次得到相同的网格。我已经看了2个小时的代码了,我想不出来。如果有人知道如何解决这个问题,我会大发雷霆。干杯 这是我的grid.php中的代码 <?php class Ecom_Pricenotify_Block_Adminhtml_Pricenotify_Grid e
<?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()));
}}
确保网格块尚未加载到相应的layout.xml文件中。我修复了它。我只需要发表评论就行了
//$this->_addContent($this->getLayout()->createBlock('pricenotify/adminhtml_pricenotify'));
从indexAction,我想我加载了两次。也许你要在布局中插入它,请检查中的pricenotify.xml adminhtml>default>default>layout 例如:
<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>
删除此块或对添加内容的行进行注释。我也面临同样的问题,但在我的情况下,这是由于
$this->setId('messages')代码>行(在Grid.php构造中)。因为magento的网格页面(用于显示通知)中已经有相同的
,因此我的网格内容被加载到此“div”标记中,因此显示网格两次。因此,我们学到的教训是,在Grid.php中设置您的“id”时不要给出通用名称,因为它可能已经出现在网格页面中。在我的例子中,它发生在Edit/Form上,我无意中在Adminhtml控制器上复制了renderLayout()
$this->renderLayout();
查找网格容器或使用网格容器和layout.xml更新您的问题。您可能应该接受此答案,以便于其他人查找。
$this->renderLayout();