magento - 我可以在magento模块中使用多个网格吗?

标签 magento grid

我可以在一个 magento 模块中使用多个网格吗?

<?php
class <Namespace>_<Module>_Block_Adminhtml_<Module> extends Mage_Adminhtml_Block_Widget_Grid_Container
{
  public function __construct()
  {
    $this->_controller = 'adminhtml_<module>';
    $this->_blockGroup = '<module>';
    $this->_headerText = Mage::helper('<module>')->__('Item Manager');
    $this->_addButtonLabel = Mage::helper('<module>')->__('Add Item');
    parent::__construct();
  }
}

所以如果我必须使用模块,我可以创建一个网格,这意味着网格严重依赖于模块,那么我们如何在同一个模块中使用多个网格呢?我找不到路,请指导我。

我在尝试让它继续前进时遇到了错误。我再详细描述一下

我的网格容器

class World_Exporter_Block_Adminhtml_Import extends Mage_Adminhtml_Block_Widget_Grid_Container{
    public function __construct()
    {
                            // Correction made on getting answer
            $this->_controller = 'adminhtml_import';
            $this->_blockGroup = 'exporter';
                            // Correction made on getting answer

            $this->_headerText = Mage::helper('exporter')->__('Item Manager');
            $this->_addButtonLabel = Mage::helper('exporter')->__('Add Item');


    }
}

还有我的网格

class World_Exporter_Block_Adminhtml_Import_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    public function __construct(){
            parent::__construct();
            $this->setId('imports');
            $this->setSaveParametersInSession(false);

                 // As it was not calling prepareCollection() I explicitly call it
                          $this->_prepareCollection();

    }

    protected function _prepareCollection(){

            $collection = Mage::getModel('exporter/imports')->getCollection();
            $this->setCollection($collection);
            return parent::_prepareCollection();
    }

    protected function _prepareColumns(){
        //  return false;
            $this->addColumn('import_id ', array(
                    'header' => Mage::helper('exporter')->__('ID'),
                    'align' => 'right',
                    'width' => '50px',
                    'index' => 'import_id ',
            ));
            $this->addColumn('import_file', array(
                    'header' => Mage::helper('exporter')->__('File Name'),
                    'align' => 'left',
                    'index' => 'import_file',
            ));
            $this->addColumn('import_time', array(
                    'header' => Mage::helper('exporter')->__('Import Time'),
                    'align' => 'left',

                    'index' => 'import_time',

            ));

            $this->addColumn('profile_id', array(
                    'header' => Mage::helper('exporter')->__('Profile'),
                    'align' => 'left',

                    'index' => 'profile_id',

            ));
            return parent::_prepareColumns();
    }

    protected function _prepareMassaction(){
            $this->setMassactionIdField('import_id');
            $this->getMassactionBlock()->setFormFieldName('imports');
            return $this;
    }

}

我的 Controller

class World_Exporter_Adminhtml_ExporterController extends Mage_Adminhtml_Controller_action{
    public function importAction(){
            $this->_initAction();
            $this->_addContent($this->getLayout()->createBlock('exporter/adminhtml_import'));
            $this->renderLayout();  

    }
}   

我的 confix xml block

<models>
    <exporter>
        <class>World_Exporter_Model</class>

        <resourceModel>exporter_mysql4</resourceModel>
    </exporter>   
       <exporter_mysql4>
                <class>World_Exporter_Model_Mysql4</class>
                <!-- declate table test -->
                <entities>
                    <profiles>
                        <table>profiles</table>
                    </profiles>
                    <imports>
                        <table>imports</table>
                    </imports>
                    <columns>
                        <table>columns</table>
                    </columns>
                </entities>
                <!-- -/- -->
            </exporter_mysql4>
  </models>

我的模型

   class World_Exporter_Model_Imports extends Mage_Core_Model_Abstract
   {
       public function _construct()
       {

           $this->_init('exporter/imports');
       }
   }

Mysql4模型

  class World_Exporter_Model_Mysql4_Imports extends Mage_Core_Model_Mysql4_Abstract
  {
     public function _construct()
     {

    $this->_init('exporter/imports', 'import_id');
     }
  }

我的收藏

  class World_Exporter_Model_Mysql4_Imports_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
  {
        public function _construct(){
                parent::_construct();
                $this->_init('exporter/imports');
        }
  }

最佳答案

是的,可以。以下是在一个模块中拥有多个网格时应采用的结构。

- Namespace
  - Module
     - Block
        - Adminhtml
           - Submodule1
              - Grid.php
           - Submodule2
              - Grid.php
           - Submodule3
              - Grid.php

关于magento - 我可以在magento模块中使用多个网格吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12300739/

相关文章:

c# - Magento API 的调用方法期望的 XML 请求负载

mysql - 在magento中批量替换产品标题

html - 如何使用 susy 在容器 div 之外拉伸(stretch)嵌套的 div 全宽?

python - 根据 "grid_location"方法,按钮有自己的坐标系?

javascript - 成员(member)资料网格

在 Magento 管理网格中使用 MySQL 计算值过滤文本类型列

magento - 如何在magento中提交表单后获取发布数据变量

javascript - Magento 时事通讯成功消息弹出

html - 如何在此网格中的所有框之间添加相等的空间?

c# - 在 Telerik mvc 网格中一键插入多条记录