将数据从表单传递到字段集
Passing data from form to fieldset
我有自定义字段集 class,例如 CustomerFieldset
。我将它添加到这样的表格中:
$someData = $this->getSomeData();
$this->add(array(
'name' => 'customfieldset',
'type' => CustomFieldset::class,
));
如何将 $someData
传递给这个字段集?
如果您想访问字段集元素并设置一个值,只需使用
$form->get('customfieldset')->get('elementName')->setvalue('value');
如果你想传递其他数据,那么在你的字段集中创建一个 属性 来保存它并创建一个 setter.
private $propertyName;
public function setProperty($value)
(
$this->propertyName = $value;
return $this;
}
并从您的表单中调用它
$form->get('customfieldset')->setProperty($value);
希望这能为您指明正确的方向。
我有自定义字段集 class,例如 CustomerFieldset
。我将它添加到这样的表格中:
$someData = $this->getSomeData();
$this->add(array(
'name' => 'customfieldset',
'type' => CustomFieldset::class,
));
如何将 $someData
传递给这个字段集?
如果您想访问字段集元素并设置一个值,只需使用
$form->get('customfieldset')->get('elementName')->setvalue('value');
如果你想传递其他数据,那么在你的字段集中创建一个 属性 来保存它并创建一个 setter.
private $propertyName;
public function setProperty($value)
(
$this->propertyName = $value;
return $this;
}
并从您的表单中调用它
$form->get('customfieldset')->setProperty($value);
希望这能为您指明正确的方向。