面向在Magento CE 1.9.2中的自定义模块的管理面板中创建表单的问题

时间:2016-05-09 14:17:53

标签: php magento magento-1.9 magento-1.9.2.1

我正在开发我的自定义模块,我面临问题。实际上我在Grid上制作了一个自定义按钮。它指向一个保存一些数据的表单。但由于某些问题,它还没有到来。

它的到来就像这样 enter image description here

这是我在网格上添加按钮的方法。

public function getMainButtonsHtml()
{
    $html=  parent::getMainButtonsHtml();
    $add_button_work = $this->getLayout()->createBlock('adminhtml/widget_button')
            ->setData(array(
               "label"=> Mage::helper('custom_abc')->__('Custom'),
                       "onclick"=> "setLocation('".$this->getUrl('*/*/newCustom')."')",
                "class"=>"save"
            ));                
    $html .= $add_button_work->toHtml();
    return $html;
}

这是我的Controller代码

public function newCustomAction()
{

    $this->_title($this->__("Custom"));
    $this->_title($this->__("Custom"));
    $this->_title($this->__("New Item"));

    $id   = $this->getRequest()->getParam("id");
    $model  = Mage::getModel("custom_abcd/abc_model")->load($id);

    $data = Mage::getSingleton("adminhtml/session")->getFormData(true);
    if (!empty($data)) {
        $model->setData($data);
    }

    Mage::register("current_custom", $model);

    $this->loadLayout();

    $this->getLayout()->getBlock("head")->setCanLoadExtJs(true);

    $this->_addBreadcrumb(Mage::helper("adminhtml")->__("custom manager"), Mage::helper("adminhtml")->__("custom manager"));
    $this->_addBreadcrumb(Mage::helper("adminhtml")->__("custom manager"), Mage::helper("adminhtml")->__("custom manager"));


    $this->_addContent($this->getLayout()->createBlock("custom_abc/adminhtml_abcd_edit_tab_customize_customform"))->_addLeft($this->getLayout()->createBlock("custom_abc/adminhtml_abcd_edit_tab_customize_edit_tab_tabs"));

    $this->renderLayout();
}

我的表单容器代码

class Custom_Abc_Block_Adminhtml_Abcd_Edit_Tab_Customize_Customform extends Mage_Adminhtml_Block_Widget_Form_Container {

public function __construct() {

    parent::__construct();
    $this->_objectId = "custom_id";
    $this->_blockGroup = "custom_abc";
    $this->_controller = "adminhtml_abc_custom";

    $this->_updateButton("save", "label", Mage::helper("custom
_abc")->__("Save Item"));

    $this->_updateButton("delete", "label", Mage::helper("custom_abc")->__("Delete Item"));


    $this->_addButton("saveandcontinue", array(
        "label" => Mage::helper("custom_abc")->__("Save And Continue Edit"),
        "onclick" => "saveAndContinueEdit()",
        "class" => "save",
            ), -100);



    $this->_formScripts[] = "function saveAndContinueEdit(){ editForm.submit($('edit_form').action+'back/edit/'); } ";
}

public function getHeaderText() {
    if (Mage::registry("current_custom") && Mage::registry("current_custom")->getId()) {

        return Mage::helper("custom_abc")->__("Edit Item '%s'", $this->htmlEscape(Mage::registry("current_custom")->getId()));
    } else {

        return Mage::helper("custom_abc")->__("Add Settings");
    }
  }

}

我的主要表格在这里 class Custom_Abc_Adminhtml_Abcd_Edit_Tab_Customize_Edit_Tab_customform extends Mage_Adminhtml_Block_Widget_Form {

protected function _prepareForm() {

    $form = new Varien_Data_Form();
    $this->setForm($form);
    $fieldset = $form->addFieldset("custom_form", array("legend" => Mage::helper("custom_abc")->__("Custom")));

    $fieldset->addField("custom_field1", "varchar", array(
        "label" => Mage::helper('custom_abc')->__("Custom Field 1"),
        "name" => "custom_field1",
    ));

    $fieldset->addField("custom_field2", "varchar", array(
        "label" => Mage::helper('custom_abc')->__("Custom Field 2"),
        "name" => "custom_field2",
    ));


    if (Mage::getSingleton("adminhtml/session")->getCustomData()) {
        $form->setValues(Mage::getSingleton("adminhtml/session")->getCustomData());
        Mage::getSingleton("adminhtml/session")->setCustomData(null);
    } elseif (Mage::registry("current_custom")) {
        $form->setValues(Mage::registry("current_custom")->getData());
    }
    return parent::_prepareForm();
}

}

0 个答案:

没有答案