我有一个symfony 3.4表单类UserForm
,我在'password_field' => false
方法中设置了选项setDefaultOptions
:
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => User::class,
'password_field' => false,
));
}
在我使用此表单的控制器中,我设置了选项:
$form = $this->createForm(UserForm::class, $user, [
'password_field' => false,
]);
通过在浏览器中加载表单,我收到以下错误消息:
The option "password_field" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".
如文档中所述,一切看起来都对我不对。有什么想法吗?
答案 0 :(得分:1)
setDefaultOptions()
已被弃用,转而使用configureOptions()
。此方法名称用于Symfony 2.x
configureOptions()
已在Symfony 3.x中使用
所以你必须替换方法名称;)
示例:
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'password_field' => false
]);
}