3

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

问题是删除操作从不传递参数“文件名”。(请参阅http://www.premasolutions.com/content/magento-manage-category-product-grid-edit-link)我有 TESTDUMP 进行验证,但它永远不会在下一页上打印。

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

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

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('*/*/');
    }
}
4

1 回答 1

5

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

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

'getter'  => 'getFilename'

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

于 2012-06-22T09:10:13.357 回答