是否可以做我想要的东西?为表单构建器创建自定义选项添加方法
我知道如何创建一个表单字段:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('field', null, array_of_options)
;
}
的add method
第三个参数是像predifined选项数组: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
。
对不起,如果我不清楚!