Magento admin grid sending data from Action to Controller

别说谁变了你拦得住时间么 提交于 2019-12-20 01:43:53

问题


I'm trying to write a custom action to run off of an admin grid that I have built. Is it possible to send a value from a column in the grid to the controller via either get or post?

I've tried googling, but I cannot find a proper explanation for this anywhere. A link to an explanation of the column settings ('getter', 'type' etc.) would also be useful if this is available.


回答1:


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



来源:https://stackoverflow.com/questions/5728842/magento-admin-grid-sending-data-from-action-to-controller

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