Magento:管理员表单行动不正确

时间:2012-04-04 17:43:59

标签: php zend-framework magento

我想在编辑客户页面添加一个新表单,到目前为止一直很好,使用重写到customer_edit_tabs我能够向页面添加选项卡和我的管理表单。代码看起来像这样。

protected function _beforeToHtml()
{

        $this->addTab('extraoptions', array(
                'label'     => Mage::helper('customer')->__('Extra options'),
                'class'     => 'ajax',
                'url'       => $this->getUrl('module/adminhtml_tabs/info', array('_current' => true)),
        ));  

这正确地添加了我的标签。从那里标签控制器上的链接:

    public function infoAction()
{
    $this->_init();
    $this->getResponse()->setBody(
    $this->getLayout()->createBlock('module/adminhtml_tabs_edit')->toHtml()
    );;
}  

这链接到Block / Adminhtml / Tabs / Edit.php

上的表单容器
class Namespace_Module_Block_Adminhtml_Tabs_Edit extends Mage_Adminhtml_Block_Widget_Form_Container{public function __construct()
{
    parent::__construct();

    $this->_objectId = 'id';
    $this->_mode = 'edit';
    $this->_blockGroup = 'module';
    $this->_controller = 'adminhtml_tabs';
    $this->_updateButton('save', 'label', Mage::helper('module')->__('Save'));

}

public function getHeaderText()
{
    return Mage::helper('module')->__('Extra Options');
}

}

My Block / Adminhtml / Tabs / Edit / Form.php

class Namespace_Module_Block_Adminhtml_Tabs_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
    {
public function __construct()
{
    parent::__construct();
}
protected function _prepareForm()
{
    $form = new Varien_Data_Form(array(
'id' => 'info_form',
                       'action' => $this->getUrl('module/adminhtml_tabs/save', array('id' => $this->getRequest()->getParam('id'))),
                       'method' => 'post',
                       'enctype' => 'multipart/form-data'
                               )
    ); 

    $fieldset = $form->addFieldset('extra_options', array('legend' => Mage::helper('module')->__('Extra Options Fieldset')));

    $fieldset2->addField('extra', 'text', array(
            'name'      => 'zip',
            'title'     => Mage::helper('module')->__('extra'),
            'label'     => Mage::helper('module')->__('extra data'),
            'maxlength' => '250',
            'required'  => false,
));
    $form->setUseContainer(true);

    }
protected function _prepareLayout()
{
    return parent::_prepareLayout();
}  

一切都很好,我在默认保存客户按钮下面有一个新按钮,但是这个保存按钮不会更新动作,所以如果我点击它,它会转到默认的客户/编辑/保存动作,它不会告诉我方法不存在它应该存在的。我的猜测是容器有问题,但我尝试了三个教程,差别不大,希望有人可以提供帮助,甚至可能有人会发现我的代码有用。

2 个答案:

答案 0 :(得分:0)

在这行代码中:

'action' => $this->getUrl('module/adminhtml_tabs/save')

您告诉Magento在该文件中查找名为module的模块,控制器别名adminhtml_tabs和saveAction()方法。

您需要确定在需要执行保存时要将用户发送到何处,然后将其放在那里(例如路径到您的控制器 - > saveAction()方法)。

答案 1 :(得分:0)

我决定创建一个新按钮以使用自定义操作进行保存。在容器上:

$this->_addButton('save', array(
        'label'     => Mage::helper('adminhtml')->__('Save Extras'),
        'onclick'   => 'document.myform.submit();',
        'class'     => 'save',
    ),-1,5);  

这就是诀窍。

相关问题