Question

This function sets up the Magento Grid to display a list of filenames with a corresponding 'Delete' action.

The problem is the Delete action never passes the parameter, 'filename.' (See http://www.premasolutions.com/content/magento-manage-category-product-grid-edit-link) I have TESTDUMP for verification but it never prints on the next page.

Is 'params' a legitimate action of 'addColumn->actions->url'?

Update: Added the construct and prepare collection for controller. Maybe it's because of the type of Collection I'm using?

class 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,
    ));
    }

}

class 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('*/*/');
    }
}
Was it helpful?

Solution

The getter of the action column is used on the collection items to retrieve the argument value for the field parameter.

I'm not sure why you are specifying the filename hardcoded or if that should work, but if you add the column configuration

'getter'  => 'getFilename'

and remove the params from the action it should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top