3

我的自定义模块网格中有以下代码。

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

我想知道有没有办法在网格中制作新的吸气剂。我这样做的目的是在 url 中传递额外的参数。

通过使用它,我得到以下编辑网址

http://domain.com/index.php/module/adminhtml_module/edit/id/5/key/a19618bbaa3ee98ed395bc2fa552de35/

如果将另一个 getter 附加到 url,例如 'getter' => 'getStoreId',

比我的网址应该是这样的:

http://domain.com/index.php/module/adminhtml_module/edit/id/5/store/5/key/a19618bbaa3ee98ed395bc2fa552de35/

任何人都可以指导我,我该怎么做。?

我尝试使用以下代码,但它不起作用。

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

2 回答 2

2

要将商店密钥添加到 url,请尝试actions

'actions'   => array(
    array(
        'caption' => Mage::helper('catalog')->__('Edit'),
        'url'     => array(
            'base'=>'*/*/edit',
            'params'=>array('store'=>$this->getRequest()->getParam('store'))
        ),
        'field'   => 'id'
    )
),

$this->getRequest()->getParam('store')根据需要更新

参考 /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',
));
于 2013-03-22T14:06:06.537 回答
1

如果要从网格中传递多个值,则可以使用自定义渲染器:

    $this->addColumn('action',
     array(
        'header'    =>  Mage::helper('module')->__('Action'),
        'width'     => '100',
        'type'      => 'text',
        'filter'    => false,
        'sortable'  => false,
        'is_system' => true,
        'renderer'  => 'Company_MyModule_Block_Adminhtml_Renderer_Actionlink',
    ));

渲染器:

class Company_MyModule_Block_Adminhtml_Renderer_Actionlink extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
  public function render(Varien_Object $row) {
    $url=$this->getUrl('*/*/edit', array('id'=>$row->getId(), 'storeId' => $row->getStoreId()));
    return sprintf("<a href='%s'>%s</a>", $url, Mage::helper('catalog')->__('Edit'));
  }
}
于 2013-12-03T11:47:20.117 回答