我创建了一个网格,其中列出了分配给订单的快递跟踪号。我在此网格中添加导出csv按钮。当我点击导出按钮时,它会出错致命错误:致电成员函数getCsv()on boolean 。
控制器代码
<?php
class Mage_OrderFulfillment_Adminhtml_TrackingnumbersController extends Mage_Adminhtml_Controller_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
public function exportCsvAction(){
$fileName = 'tracking_numbers.csv';
$content = $this->getLayout()->createBlock('orderfulfillment/adminhtml_trackingnumbers_grid');
$this->_prepareDownloadResponse($fileName, $content->getCsv());
}
}
网格代码
<?php
class Mage_OrderFulfillment_Block_Adminhtml_Trackingnumbers_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('mage_orderfulfillment_trackingnumbers_grid');
$this->setDefaultSort('id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('orderfulfillment/trackingnumbers')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => Mage::helper('OrderFulfillment')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'id',
));
$this->addColumn('tracking_number', array(
'header' => Mage::helper('OrderFulfillment')->__('Tracking Number'),
'width' => '150px',
'index' => 'tracking_number',
));
$this->addExportType('*/*/exportCsv', Mage::helper('OrderFulfillment')->__('CSV'));
return parent::_prepareColumns();
}
}
答案 0 :(得分:0)
//Update below function :
public function exportCsvAction() {
$fileName = 'tracking_numbers.csv';
$content = $this->getLayout()->createBlock('orderfulfillment/adminhtml_trackingnumbers_grid')->getCsv(); //Update this
$this->_sendUploadResponse($fileName, $content); //Update this
}