我现在创建了一个成功显示数据的网格,现在我想创建另一个网格我的文件和代码结构如下
包含网格数据代码的网格类
<?php
class Shop_Shop_Block_Adminhtml_Shop_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('shopGrid');
$this->setDefaultSort('id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToSelect('*');
$collection->joinTable('catalog/category_product', 'product_id=entity_id', array(
'my_cat' => 'category_id'
), null, 'left');
$collection->joinTable('catalog_category_entity_varchar', 'entity_id=my_cat', array(
'mv' => 'value'
), null, 'left');
$collection->groupByAttribute('entity_id');
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => 'Product ID',
'align' => 'left',
'width' => '10',
'index' => 'entity_id'
));
$this->addColumn('name', array(
'header' => 'Name',
'align' => 'left',
'index' => 'name'
));
$this->addColumn('price', array(
'header' => 'Price',
'align' => 'left',
'class' => 'myid',
'index' => 'price'
));
$this->addColumn('category', array(
'header' => 'Category',
'align' => 'left',
'index' => 'mv'
));
$this->addColumn('edit', array(
'header' => Mage::helper('catalog')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Edit'),
'url' => array(
'base' => '../../admin/catalog_product/edit'
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores'
));
$this->addColumn('delete', array(
'header' => Mage::helper('catalog')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Delete'),
'url' => array(
'base' => '*/*/../../admin/catalog_product/delete'
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores'
));
return parent::_prepareColumns();
}
}
?>
<?php
class Shop_Shop_Block_Adminhtml_Shop extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_shop';
$this->_blockGroup = 'shop';
$this->_headerText = 'My product';
}
}
?>
我的商店xml,用于显示我的模板和网格
<?xml version="1.0" encoding="UTF-8"?>
<layout version="1.0.1">
<shop_index_index>
<reference name="content">
<block name="shop_index" type="page/html" template="shop/index.phtml" />
</reference>
<reference name="head">
<action method="addJs">
<script>shop/jquery-2.1.4.min.js</script>
</action>
<action method="addCss">
<stylesheet>shop/shop-admin.css</stylesheet>
</action>
<action method="addJs">
<script>shop/shop-admin.js</script>
</action>
</reference>
</shop_index_index>
<shop_index_main>
<reference name="content">
<block name="shop_main" type="page/html" template="shop/main.phtml" />
<block name="shop_grid" type="shop/adminhtml_grid" />
</reference>
<reference name="head">
<action method="addJs">
<script>shop/jquery-2.1.4.min.js</script>
</action>
<action method="addCss">
<stylesheet>shop/shop-admin.css</stylesheet>
</action>
<action method="addJs">
<script>shop/shop-admin.js</script>
</action>
</reference>
</shop_index_main>
</layout>
我已经成功创建了一个网格,但现在我想创建另一个网格。请帮助并提供此问题的任何解决方案