magento 1.9自定义模块网格

时间:2019-01-31 12:41:42

标签: magento-1.9

我是magento 1.9的新手。我已经为定制模块创建了定制网格。但是我没有得到网格表

app / etc / modules / Bss_AdminGrid.xml

     <?xml version="1.0"?>
  <config>
        <modules>
            <Bss_AdminGrid>
                <active>true</active>
                <codePool>local</codePool>
            </Bss_AdminGrid>
        </modules>
     </config>

app / code / local / Bss / AdminGrid / etc / config.xml

    <?xml version="1.0"?>
<config>
    <modules>
        <Bss_AdminGrid>
            <version>1.0.0</version>
        </Bss_AdminGrid>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <bss_admingrid before="Mage_Adminhtml">Bss_AdminGrid_Adminhtml</bss_admingrid>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <admingrid>
                    <file>admingrid.xml</file>
                </admingrid>
            </updates>
        </layout>
    </adminhtml>
    <global>
        <helpers>
            <admingrid>
                <class>Bss_AdminGrid_Helper</class>
            </admingrid>
        </helpers>
        <blocks>
            <admingrid>
                <class>Bss_AdminGrid_Block</class>
            </admingrid>
        </blocks>   
        <models>
            <admingrid>
                <class>Bss_AdminGrid_Model</class>
                <resourceModel>admingrid_resource</resourceModel>
            </admingrid>
            <admingrid_resource>
                <class>Bss_AdminGrid_Model_Resource</class>
                <entities>
                    <admingrid_table>
                        <table>admingrid_table</table>
                    </admingrid_table>
                </entities>
            </admingrid_resource>
            <!-- Resource model to create a database table -->
            <admingrid_resource>
                <class>Bss_AdminGrid_Model_Resource</class>
                <entities>
                    <adgrid>
                        <table>admingrid_adgrid</table>
                    </adgrid>                    
                </entities>
            </admingrid_resource>
        </models>

        <resources>
            <admingrid_setup>
                <setup>
                    <module>Bss_AdminGrid</module>
                </setup>
            </admingrid_setup>
            <connection>
                <use>core_setup</use>
            </connection>

            <admingrid_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </admingrid_write>

            <admingrid_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </admingrid_read>
        </resources>

    </global>

    <layout>
        <updates>
            <admingrid>
                <file>bss/admingrid.xml</file>
            </admingrid>
        </updates>
    </layout>
</config>

应用程序\代码\本地\ Bss \ AdminGrid \ Helper \ Data.php

<?php

class Bss_AdminGrid_Helper_Data extends Mage_Core_Helper_Abstract
{
}

应用/代码/本地/Bss/AdminGrid/etc/adminhtml.xml

 <?xml version="1.0"?>
<config>
<menu>
<admingrid module="admingrid" translate="title">
        <title>AdminGrid</title>
        <sort_order>100</sort_order>
        <children>
          <adgrid module="admingrid" translate="title">
            <title>Manage Items</title>
            <sort_order>0</sort_order>
            <action>*/adgrid</action>
          </adgrid>
        </children>
      </admingrid>
    </menu>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <admingrid translate="title" module="admingrid">
              <title>AdminGrid</title>
              <sort_order>1000</sort_order>
              <children>
          <admingridbackend translate="title">
            <title>Manage Items</title>
          </admingridbackend>
              </children>
            </admingrid>
          </children>
        </admin>
      </resources>
    </acl>
</config>

应用程序\代码\本地\ Bss \ AdminGrid \ Model \ Adgrid.php

    <?php

class Bss_AdminGrid_Model_Adgrid extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {  
        $this->_init('admingrid/adgrid');
    }  
}

app \ code \ local \ Bss \ AdminGrid \ Model \ Mysql4 \ Adgrid.php

<?php

class Bss_AdminGrid_Model_Mysql4_Adgrid extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {
        $this->_init('admingrid/adgrid', 'id');
    }
}

应用程序\代码\本地\ Bss \ AdminGrid \ Model \ Mysql4 \ Adgrid \ Collection.php

<?php

class Bss_AdminGrid_Model_Mysql4_Adgrid_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    protected function _construct()
    {  
        $this->_init('admingrid/adgrid');
    }  
}

应用程序\代码\本地\ Bss \ AdminGrid \ Model \ Resource \ Adgrid.php

<?php

class Bss_AdminGrid_Model_Resource_Adgrid extends Mage_Core_Model_Resource_Db_Abstract
{
    protected function _construct()
    {  
        $this->_init('admingrid/adgrid', 'id');
    }  
}

app \ code \ local \ Bss \ AdminGrid \ Block \ Adminhtml \ Adgrid.php

<?php


class Bss_AdminGrid_Block_Adminhtml_Adgrid extends Mage_Adminhtml_Block_Widget_Grid_Container {
    public function __construct()
    {
        $this->_blockGroup = 'admingrid';
        $this->_controller = 'adminhtml_adgrid';
        $this->_headerText = $this->__('Admin Grid');
         $this->_addButtonLabel = Mage::helper('admingrid')->__('Add Attribute Options');
        parent::__construct();
    }
}

应用程序\代码\本地\ Bss \ AdminGrid \ Block \ Adminhtml \ Adgrid \ Grid.php

<?php


class Bss_AdminGrid_Block_Adminhtml_Adgrid_Grid extends Mage_Adminhtml_Block_Widget_Grid {
     public function __construct()
    {
        parent::__construct();

        $this->setDefaultSort('adminGrid_id');
        $this->setId('adminGrid');
        $this->setDefaultDir('asc');
        $this->setSaveParametersInSession(true);
    }
    protected function _getCollectionClass()
    {
        return 'admingrid/adgrid_collection';
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $this->setCollection($collection);

        return parent::_prepareCollection();
    }
     protected function _prepareColumns()
    {

        $this->addColumn('id',
            array(
                'header'=> $this->__('ID'),
                'align' =>'right',
                'width' => '50px',
                'index' => 'id'
            )
        );

        $this->addColumn('items',
            array(
                'header'=> $this->__('Items'),
                'index' => 'items'
            )
        );         
        return parent::_prepareColumns();
    }   
}

app \ code \ local \ Bss \ AdminGrid \ controllers \ Adminhtml \ AdgridController.php

<?php

class Bss_AdminGrid_Adminhtml_AdgridController extends Mage_Adminhtml_Controller_Action
{

    protected function _isAllowed()
    {
        return Mage::getSingleton('admin/session')->isAllowed('admingrid/adgrid');
    }


    public function indexAction()
    {


           $this->loadLayout();
          $this->renderLayout();
    }
     public function gridAction()
    {
        $this->loadLayout();
        $this->getResponse()->setBody(
            $this->getLayout()->createBlock('bss_admingrid/adminhtml_adgrid_grid')->toHtml()
        );
    }

    public function exportCsvAction()
    {
        $fileName = 'admingrid.csv';
        $grid = $this->getLayout()->createBlock('bss_admingrid/adminhtml_adgrid_grid');
        $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
    }

    public function exportExcelAction()
    {
        $fileName = 'admingrid.xml';
        $grid = $this->getLayout()->createBlock('bss_admingrid/adminhtml_adgrid_grid');
        $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
    }

}

应用程序\代码\本地\ Bss \ AdminGrid \ sql \ admingrid_setup \ mysql4-install-1.0.0.php

<?php 

$installer = $this;
$installer->startSetup();
$installer->run("
    DROP TABLE IF EXISTS {$this->getTable('admingrid/adgrid')};
    CREATE TABLE {$this->getTable('admingrid/adgrid')} (
      `id` int(11) unsigned NOT NULL auto_increment,
      `item` text NULL ,
      PRIMARY KEY (`Id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
        ");
$installer->endSetup();

app \ design \ adminhtml \ default \ default \ layout \ admingrid.xml

<?xml version="1.0"?>
<layout version="0.1.0">
  <adminhtml_adgrid_index>
    <reference name="content">
      <block type="admingrid/adminhtml_adgrid" name="adgrid"/>
    </reference>
  </adminhtml_adgrid_index>
</layout>

输出我得到的信息:

enter image description here

我希望这是我的输出 enter image description here 谁能说我在哪里犯错?预先感谢

1 个答案:

答案 0 :(得分:0)

受保护的函数_prepareCollection(){$ collection = Mage :: getModel(“ admingrid / adgrid”)-> getCollection(); $ this-> setCollection($ collection);返回parent :: _ prepareCollection(); }