0
我嘗試在網格列中獲取foreach結果(我有結果,但我不知道如何將它放入每個類別ID的列中)。如何將foreach結果添加到列網格?
我grid.php
public function _prepareCollection()
{
$subcategories = Mage::getModel('catalog/category')
->setStoreId(Mage::app()->getStore()->getId())
->getCollection()
->addAttributeToSelect('*')
->setOrder('parent_id', 'ASC');
$categories = array();
foreach ($subcategories as $category){
//do something with $category and put it in Route column
if ($category['level'] > 1) {
$categories[$category['entity_id']] = array('category_route' => $category['level'] == 2 ? $category['name'] : $categories[$category['parent_id']]['category_route'] ." -> ". $category['name']);
}
var_dump($categories[$category['entity_id']]);
}
$collection = Mage::getModel('thorleif/commerciaux')->getCollection();
$collection->addFieldToFilter('entity_id',array("nin"=>array(1,2)));
$this->setCollection($collection);
return parent::_prepareCollection();
}
public function _prepareColumns()
{
$this->addColumn('entity_id',
array(
'header' => 'ID',
'align' => 'left',
'width' => '10%',
'index' => 'entity_id'
)
);
$this->addColumn('name',
array(
'header' => 'Category Name',
'align' => 'left',
'index' => 'name'
)
);
$this->addColumn('route',
array(
'header' => 'Route',
'align' => 'left',
'index' => array($category['name'] .'>'. $category['name'])
)
);
它就像this