【问题标题】:magento adminhtml custom module it's showing the grid twicemagento adminhtml 自定义模块它显示了两次网格
【发布时间】:2011-08-03 13:26:48
【问题描述】:

按照本指南Custom Module with Custom Database Table,我是magento的新手

我已将我已经存在的模块实现到后端 adminhtml。我正在从数据库中获取东西并在 adminhtml 页面上显示 ot。一切正常,除了我在 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();
  }

【问题讨论】:

  • 发现网格容器或使用网格容器和 layout.xml 更新您的问题。

标签: magento magento-1.4 magento-1.5


【解决方案1】:

也许你将它插入到布局中,检查 pricenotify.xml in

adminhtml>default>default>布局。

如:

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

删除此块或注释您添加内容的行。

【讨论】:

    【解决方案2】:

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

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

    从 indexAction 我猜我加载了两次。

    【讨论】:

    • 您可能应该接受这个答案,以便其他人更容易找到。
    【解决方案3】:

    确保网格块尚未加载到相应的 layout.xml 文件中。

    【讨论】:

      【解决方案4】:

      好吧,我遇到了同样的问题,但在我的情况下,这是由于 $this-&gt;setId('messages'); 行(在您的 Grid.php 构造中)。因为 magento 在其网格页面(用于显示通知)中已经有相同的&lt;div id="messages"&gt;&lt;/div&gt;,因此我的网格内容被加载到这个“div”标签中,因此显示了两次网格。所以吸取的教训是在 Grid.php 中设置您的“id”时不要给出通用名称,这可能已经存在于网格页面中。

      【讨论】:

        【解决方案5】:

        在我的例子中,它发生在 Edit/Form 上,我无意中在我的 Adminhtml 控制器上复制了 renderLayout()。

        $this->renderLayout();
        

        【讨论】:

          猜你喜欢
          • 2014-07-09
          • 1970-01-01
          • 1970-01-01
          • 2012-02-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-18
          相关资源
          最近更新 更多