Magento Grid :使用addColumn Actions的更好方法


Magento Grid : Better way of using addColumn Actions?

此函数设置 Magento 网格以显示具有相应"删除"操作的文件名列表。

问题是删除操作从不传递参数"文件名"。 (见 http://www.premasolutions.com/content/magento-manage-category-product-grid-edit-link) 我有用于验证的测试转储,但它永远不会在下一页上打印。

"

params"是"addColumn->actions->url"的合法操作吗?

更新:添加了控制器的构造和准备集合。 也许是因为我使用的收藏类型?

类Rogue_Googlemerchant_Block_Adminhtml_Exporter_Grid

Rogue_Googlemerchant_Block_Adminhtml_Exporter_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
    parent::__construct();
    $this->setId('googlemerchantGrid');
    // This is the primary key of the database
    $this->setDefaultSort('filename');
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
    $basePath = Mage::getBaseDir('base');
    $feedPath = $basePath . '/opt/googlemerchant/';
    $errPath = $basePath . '/var/log/googlemerchant/';
    $flocal = new Varien_Io_File();
    $flocal->open(array('path' => $feedPath));
    $dataCollection = new Varien_Data_Collection();
    foreach ($flocal->ls() as $item) {
        $dataObject = new Varien_Object();
        $dataObject->addData(
            array(
                'filename'     => $item['text'],
                'size'         => $item['size'] / 1000 . ' kb',
                'date_modified'=> $item['mod_date']
            )
        );
        $dataCollection->addItem($dataObject);
    }
    $this->setCollection($dataCollection);
    return parent::_prepareCollection();
}
    protected function _prepareColumns()
    {
        $this->addColumn('filename', array(
          'header'    => Mage::helper('googlemerchant')->__('File'),
          'align'     =>'left',
          'index'     => 'filename',
          'width'     => '200px',
        ));
        $this->addColumn('action', array(
            'header'  => Mage::helper('googlemerchant')->__('Action'),
            'width'   => '50px',
            'type'    => 'action',
    //      'getter'  => 'getId',
            'actions' => array(
                array(
                    'caption' => Mage::helper('googlemerchant')->__('Delete'),
                    'url'     =>
                        array(
                            'base'   => '*/*/delete',
                            'params' => array('filename' => 'TESTDUMP')
                        ),
                    'field'   => 'filename'
                )
            ),
            'filter'    => false,
            'sortable'  => false,
    //       'index'     => 'filename',
    //       'is_system' => true,
    ));
    }
}

类Rogue_Googlemerchant_Adminhtml_ExporterController

class Rogue_Googlemerchant_Adminhtml_ExporterController extends Mage_Adminhtml_Controller_Action
{
    public function deleteAction()
    {
        $filename = $this->getRequest()->getParam('filename');
        $basePath = Mage::getBaseDir('base');
        $feedPath = $basePath . '/opt/googlemerchant/';
        $errPath = $basePath . '/var/log/googlemerchant/';
        $flocal = new Varien_Io_File();
        $flocal->open(array('path' => $feedPath));
d($filename);
        if ($filename) {
            try{
                $flocal->rm($filename);
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('googlemerchant')->__('The file has been deleted.'));
                $this->_redirect('*/*/');
            }
            catch (Mage_Core_Exception $e) {
                $this->log($e);
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/index');
                return;
            }
        }
die('here');
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Unable to find the file to delete.'));
        $this->_redirect('*/*/');
    }
}

操作列的getter用于集合项,以检索field参数的参数值。

我不确定为什么要指定硬编码的文件名,或者这是否应该有效,但是如果您添加列配置

'getter'  => 'getFilename'

并从它应该起作用的操作中删除params