我正在尝试编写一个自定义操作来运行我构建的管理网格。是否可以通过 get 或 post 将网格中的列中的值发送到 Controller ?
我尝试过谷歌搜索,但在任何地方都找不到正确的解释。如果可用的话,指向列设置(“getter”、“type”等)说明的链接也会很有用。
最佳答案
将此代码添加到您的 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,
));
这将构建一个“编辑”URL,并将所选行的 ID 作为 URL 的一部分。它看起来像 <frontname>/<controllername>/edit/id/<value>
哪里value
由 getter getId()
返回。
getter 字段将执行任何标准的 Magento magic getter,即任何属性都是可获取的。所以你可以有getName
或getProductUrl
或getIsLeftHanded
如果您愿意并且您的 Controller 可以解析该属性。
然后 Controller 可以使用 Mage::app()->getRequest()->getParam('attributename');
检索传递的值
就文档/教程而言,请阅读 this article在@AlanStorm 的网站上,因为它可能会有所帮助。
HTH,
京东
关于Magento 管理网格将数据从 Action 发送到 Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5728842/