在您的形式称为MyForm
创建以下部件:
$this->widgetSchema ['my_widget'] = new sfWidgetFormChoice(array('multiple' => true, 'expanded' => true, 'choices' => my_choices, 'renderer_class' => 'sfWidgetFormSelectCheckbox', 'renderer_options' => array('formatter' => array('MyForm', 'MyFormatter'))));
$this->validatorSchema ['my_widget'] = new sfValidatorChoice(array('multiple' => true, 'choices' => array_keys(my_choices), 'required' => false));
然后添加以下格式化方法叫MyFormatter
:
public static function MyFormatter($widget, $inputs) {
$result = '<table>';
foreach ($inputs as $input) {
$result .= '<tr><td>' . $input ['label'] . ' ' . $input ['input'] . '</td></tr>';
}
$result .= '</table>';
return $result;
}
我通过设置renderer_class
选项用于被渲染为复选框的选择到小工具定义中的sfWidgetFormSelectCheckbox
,您可以使用sfWidgetFormSelectRadio
将其呈现为单选按钮,并且可以通过更改01从另一个表单调用另一个格式化工具。