Magento管理网格将数据从Action发送到Controller [英] Magento admin grid sending data from Action to Controller

查看:205
本文介绍了Magento管理网格将数据从Action发送到Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编写一个自定义操作来运行我已经构建的管理网格。是否有可能通过get或post从网格中的列向控制器发送值?



我试过Google搜索,但找不到合适的解释为此在任何地方。如果可以的话,一个解释列设置('getter','type'等)的链接也会很有用。

解析方案

  $ this-> addColumn('action',
array(
'header'=> Mage :: helper('yourmodulename') - > __('Action'),
'width'=>'100',
'type'=>'action',
'getter'=>'getId',
'actions'=>数组(
array(
'caption' => Mage :: helper('yourmodulename') - > __('Edit'),
'url'=> array('base'=>'* / * / edit'),
'field'=>'id'

),
'filter'=> false,
'sortable'=> false,
'index'=>'stores',
'is_system'=>真,
));

这将构建一个编辑网址,并将所选行的ID作为网址的一部分。它看起来像< $ name> /< controllername> / edit / id /< value> 其中由getter getId()返回。

getter字段将执行任何标准的Magento魔术获得者,即任何属性都可以获得。因此,如果你有 getName getProductUrl getIsLeftHanded 想要和你的控制器可以解析属性。然后控制器可以使用 Mage :: app() - > getRequest() - > getParam('attributename')来检索传递的值。 );



在文档/教程方面,请阅读这篇文章在@AlanStorm的网站上,因为它可能有所帮助。

HTH,

JD


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.

解决方案

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

这篇关于Magento管理网格将数据从Action发送到Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆