2

我已经成功创建了我的第一个管理网格。添加新项目时它工作正常。但是,当我想编辑一个项目时,奇怪的DELETE是,按钮不见了。更糟糕的是,当我单击SAVE按钮时,它会创建一个新项目而不是保存当前项目。我做错了什么?

我不确定要查看哪个文件,因此我不知道必须在此处发布哪些代码。如果我把所有文件中的所有代码都放了,那就太多了。请指教。

更新:不知道为什么,但现在SAVE按钮不再重新创建。所以我可以平静地编辑一个项目。但是,DELETE按钮仍然丢失。

4

4 回答 4

12

在游戏后期,但希望这将有助于谷歌员工。

您的_objectId属性是否正确设置为 URL 中的相应参数?

$this->_objectId = 'id';

其中 ID 指的是 URL 的这一部分:

/module/adminhtml_controller/edit/ id /1/

查看父类Mage_Adminhtml_Block_Widget_Form_Container::__construct

...
$objId = $this->getRequest()->getParam($this->_objectId);

        if (! empty($objId)) {
            $this->_addButton('delete', array(
                'label'     => Mage::helper('adminhtml')->__('Delete'),
                'class'     => 'delete',
                'onclick'   => 'deleteConfirm(\''. Mage::helper('adminhtml')->__('Are you sure you want to do this?')
                    .'\', \'' . $this->getDeleteUrl() . '\')',
            ));
        }
...

我们可以看到,如果$objId为空,则不会添加删除按钮。

于 2013-11-13T22:35:41.343 回答
4

在挣扎之后,罪魁祸首是因为我把 parent::__construct(); 在顶部(就在 __construct() 方法之后。相反,它应该放在 $this->_controller 行之后。Geezz...

于 2012-08-25T17:35:45.210 回答
1

***如果您不想在网格中显示“添加新”按钮,请从 magento 管理员中删除或重命名添加新的保存继续删除按钮。添加新按钮位于网格页面的右上角。

重命名“添加新”按钮

以下是将“添加新”文本重命名为您需要的任何内容的步骤(例如,“添加报告”):-

  • 转到 YourNamespace -> YourModule -> 块 -> Adminhtml -> enter code hereYourFile.php
  • 在此文件的构造函数中添加以下代码:-

    $this-> addButtonLabel = Mage::helper('yourmodulename')->_ ('Add Report');

删除“添加新”按钮 以下是删除“添加新”按钮的步骤:-

  • 转到 YourNamespace -> YourModule -> 块 -> Adminhtml -> YourFile.php
  • 在此文件的构造函数中添加以下代码(它应该就在对父构造函数的调用下方):-

    父::__construct(); $this->_removeButton('add');

在edit.php中

parent::__construct();
$this->_removeButton('delete');
$this->_removeButton('save');
$this->_removeButton('back');

在 grid.php 中

parent::__construct();
$this->_removeButton('add');
于 2014-07-21T06:17:55.360 回答
0

试试你的 Grid.php:

    public function getRowUrl($row){
    return $this->getUrl('*/*/form', array('id' => $row->getId()));
}
于 2012-08-24T14:57:18.140 回答