2011-04-20 83 views
2

我正在嘗試編寫一個自定義操作來運行我已經構建的管理網格。是否可以通過get或post從網格中的列向控制器發送一個值?Magento管理網格將數據從Action發送到控制器

我試過Google搜索,但我無法在任何地方找到合適的解釋。如果可用,則對列設置(「getter」,「類型」等)的解釋的鏈接也是有用的。

回答

9

將此代碼添加到您的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, 
    )); 

,將建立與所選行的id的「編輯」 URL作爲URL的一部分。它看起來像<frontname>/<controllername>/edit/id/<value>,其中value由獲取者getId()返回。

getter字段將執行任何標準的Magento魔術獲得者,即任何屬性都是可以獲得的。所以你可以有getNamegetProductUrlgetIsLeftHanded如果你想和你的控制器可以解析屬性。

控制器就可以檢索使用Mage::app()->getRequest()->getParam('attributename');

在文檔/教程的術語,其傳遞的值,有this article讀@AlanStorm的網站上,因爲它可能會有所幫助。

HTH,
JD

+0

感謝您的幫助,這幾乎是所有我需要知道。我沒有意識到你可以使用'getter'來挑選任何屬性。 – Geoff 2011-04-20 12:27:55

+0

吸氣劑對我來說也是新的,但正是我所需要的。 – 2012-10-04 03:26:51

+0

如果我想獲得多個getter方法怎麼辦如果我想在URL中傳遞多個不能訪問的參數,可以使用Mage :: app() - > getRequest() - > getParam('attributename') – shashank 2016-02-02 13:10:19

相關問題