更新时间:2023-02-05 16:22:14
这实际上非常复杂;理想情况下,您的网格需要成为实例化表单的容器的一部分,并通过选项卡"部分进行调用.保存按钮通常是自定义phtml模板的一部分,该模板与通过Adminhtml中的控制器操作调用的布局块一起调用.
This is actually quite complex; ideally your grid needs to be part of a Container which instantiates a Form, and is called via a Tab section. The save buttons are usually some part of a custom phtml template that is invoked along with the layout block that is called via the controller action in your Adminhtml.
这个form.phtml可能非常简单,但通常包含一些可格式化保存url(请参阅下文)并收集提交数据的javascript.
This form.phtml can be very simple but usually contains some javascript that formats the save url (see below) and gathers the submission data.
Form.php
构造函数:
public function __construct()
{
parent::__construct();
$this->setTemplate('your/adminhtml/edit/form.phtml');
}
和_prepareLayout方法:
And the _prepareLayout method:
protected function _prepareLayout()
{
// Save button
$this->setChild('save_button',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('catalog')->__('Save Category'),
'onclick' => "formSubmit('" . $this->getSaveUrl() . "', true)",
'class' => 'save'
))
);
您的保存按钮是将提交定向到正确的控制器的按钮.在上面的示例中,它们使用getSaveUrl作为这些块类的方法.您也可以对此进行硬编码或像在其他地方一样使用$this->getUrl('*/*/save')
.单击此保存按钮将序列化表格:
Your save button is what directs the submission to the correct controller. In this example above they use getSaveUrl as a method of these block classes. You can also hard code this or use $this->getUrl('*/*/save')
as you probably do elsewhere. Clicking this save button will serialize the form:
form.phtml
默认文件仅具有:
<div class="entry-edit">
<?php echo $this->getFormHtml();?>
</div>
<?php echo $this->getChildHtml('form_after');?>
包含可编辑的帖子数据的扩展form.phtml文件将执行以下操作:
An extended form.phtml file that includes editible post data does something like this:
<div class="entry-edit">
<?php echo $this->getFormHtml();?>
</div>
<?php echo $this->getChildHtml('form_after');?>
<script>
function formSubmit(url){
var elements = $('[yourformid]').select('input');
var serialized = Form.serializeElements(elements, true);
window.location(url + '?' + serilized.[element_name].join(','));
}
</script>
我还没有测试上面代码的每个部分,但是理论是扎实的,这就是我在这些情况下要做的事情.
I haven't tested every part of the above code, but the theory is solid, and it's what I do in these situations.
干杯.