2

1 つの 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();
  }
}

モジュールを使用するように制限されている場合は、1 つのグリッドを作成できます。つまり、グリッドはモジュールに大きく依存しているため、同じモジュールで複数のグリッドを使用するにはどうすればよいでしょうか? 道がわかりません、教えてください。

続行しようとするとエラーが発生します。もっと説明してる

マイ グリッド コンテナ

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

}

私のコントローラー

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チャンク

<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');
        }
  }
4

2 に答える 2

3

はい、できます。以下は、1 つのモジュールに複数のグリッドを含めるために使用する必要がある構造です。

- Namespace
  - Module
     - Block
        - Adminhtml
           - Submodule1
              - Grid.php
           - Submodule2
              - Grid.php
           - Submodule3
              - Grid.php
于 2012-09-06T13:42:48.923 に答える
1

グリッド コンテナーを確認します。

class World_Exporter_Block_Adminhtml_Import extends Mage_Adminhtml_Block_Widget_Grid_Container{
    public function __construct()
    {
        //should be $this->_controller = 'adminhtml_import';
        $this->_controller = 'adminhtml_exporter';
        //should be $this->_blockGroup = 'exporter';
        $this->_blockGroup = 'import';
        $this->_headerText = Mage::helper('exporter')->__('Item Manager');
        $this->_addButtonLabel = Mage::helper('exporter')->__('Add Item');
        parent::__construct();
    }
}

$this->_controller = 'adminhtml_exporter';する必要があります$this->_controller = 'adminhtml_import';

$this->_blockGroup = 'import';する必要があります$this->_blockGroup = 'exporter';

なんで?名前からすると少しあいまいです。はい、コントローラーという名前ですが、その背後にあるものを確認する必要があります。

Mage_Adminhtml_Block_Widget_Grid_Container

protected function _prepareLayout()
{
    $this->setChild( 'grid',
        $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
        $this->_controller . '.grid')->setSaveParametersInSession(true) );
    return parent::_prepareLayout();
}

コンテナは子を作成します (子はグリッドです):

$this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid', $this->_controller . '.grid')

以前のコードは以下を作成します。

$this->getLayout()->createBlock( 'import/adminhtml_exporter_grid', 'adminhtml_exporter.grid')

これは正しくありません。次のようにする必要があります。

$this->getLayout()->createBlock( 'exporter/adminhtml_import_grid', 'adminhtml_exporter.grid')

あなたのグリッドはWorld_Exporter_Block_Adminhtml_Import_Grid

于 2012-09-07T13:46:20.670 に答える