Magento admin grid sending data from Action to Controller

余生长醉 提交于 2019-12-01 20:33:54

Add this code to your Grid.php:

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

That will build an "Edit" URL with the Id of the selected row as part of the URL. It will look something like <frontname>/<controllername>/edit/id/<value> where value is returned by the getter getId().

The getter field will execute any of the standard Magento magic getters, ie any attribute is gettable. So you could have getName or getProductUrl or getIsLeftHanded if you wanted and your controller can parse the attribute.

The controller can then retrieve that passed value using Mage::app()->getRequest()->getParam('attributename');

In terms of documentation/tutorials, have a read of this article on the website of @AlanStorm as it might help.

HTH,
JD

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!