【发布时间】:2013-10-28 01:47:58
【问题描述】:
有没有可能做我想做的事?
我知道如何创建表单域:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('field', null, array_of_options)
;
}
add method 的第三个参数是一个预定义选项数组,例如:label、attr 等……如果你这样做:
$builder
->add('field', null, array('my_option' => 'my value'));
你会得到这个错误:
The option "my_option" does not exist. Known options are: "action", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "grouping", "inherit_data", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "mapped", "max_length", "method", "pattern", "post_max_size_message", "precision", "property_path", "read_only", "required", "rounding_mode", "translation_domain", "trim", "validation_groups", "virtual"
我已经阅读并理解了this,但这不是我想要的。我不想从控制器传递createForm 方法中的选项。
我想要的是为add method中的第三个参数的数组创建一个自定义option。
如果我不清楚,对不起!
【问题讨论】:
标签: symfony formbuilder