1

I have this code:

$grid->addColumn('action',array(
            'header'    => $this->__('Action'),
            'type'      => 'action',
            'action'    => array(
                'label'     => $this->__('Join Program'),
                'url'       => 'urlstring/index/join',
                'name'      => 'id',
                'field'     => 'program_id'             
            )
        ));

I want to set multiple url parameters. So in other word I need to achieve something like this:

$grid->addColumn('action',array(
            'header'    => $this->__('Action'),
            'type'      => 'action',
            'action'    => array(
                'label'     => $this->__('Join Program'),
                'url'       => 'urlstring/index/join',
                'name'      => 'id',
                'field'     => 'program_id',
                'name'      => 'PARAMETER2',
                'field'     => 'PARAMETER2'             
            )
        ));

This does not work. What is the proper way to achieve this? How can I set PARAMETER2?

1

I found some examples from Magento core /app/code/core/Mage/Adminhtml/Block/Backup/Grid.php :

$this->addColumn('action', array(
            'header'    => Mage::helper('backup')->__('Action'),
            'type'      => 'action',
            'width'     => '80px',
            'filter'    => false,
            'sortable'  => false,
            'actions'   => array(array(
                'url'       => $this->getUrl('*/*/delete', array('time' => '$time', 'type' => '$type')),
                'caption'   => Mage::helper('adminhtml')->__('Delete'),
                'confirm'   => Mage::helper('adminhtml')->__('Are you sure you want to do this?')
            )),
            'index'     => 'type',
            'sortable'  => false
        ));

or from /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php :

$this->addColumn('action',
            array(
                'header'    => Mage::helper('catalog')->__('Action'),
                'width'     => '50px',
                'type'      => 'action',
                'getter'     => 'getId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('catalog')->__('Edit'),
                        'url'     => array(
                            'base'=>'*/*/edit',
                            'params'=>array('store'=>$this->getRequest()->getParam('store'))
                        ),
                        'field'   => 'id'
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'stores',
        ));

We see here an easiest way to send multiple parameters through url

0
 $this->addColumn('edit', array(
        'header' => Mage::helper('yourmodulename')->__('Edit'),
        'width' => '80',
        'type' => 'action',
        'getter' => 'getId',
        'actions' => array(
            array(
                'caption' => Mage::helper('yourmodulename')->__('Edit'),
                'url' => array('base' => 'modulename/adminhtml_controllername/Action'),
                'field' => 'id'
            )
        ),
        'filter' => false,
        'sortable' => false,
        'index' => 'stores',
        'is_system' => true,
    )); 

You can add number of actions you need by using above format

0

I found a nicer way to do this. It's with render.

Create a function like this:

public function getJoinUrl($row) {
        return sprintf('<a href="%s" title="%s">%s</a>'
                , $this->getUrl('urlstring/index/join', array('id' => $row->getId(),'PARAMETER2NAME' => PARAMETER2))
                , $this->__('Join')
                , $this->__('Join')
        );
    }

and render grid like this:

$grid->addColumn('action',array(
            'header'    => $this->__('Action'),
            'render'    => 'getJoinUrl',
            'filter_index'  => 'IF (n.value IS NULL, main_table.name, n.value)'
        ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.