Symfony 表单:选项不起作用
Symfony Forms: options not working
我有一个 symfony 3.4 格式 class UserForm
并且我在 setDefaultOptions
方法中设置了选项 'password_field' => false
:
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".
如文档中所述,我认为一切正常。有什么想法吗?
setDefaultOptions()
已被弃用,取而代之的是 configureOptions()
。这个方法名在 Symfony 中被使用 2.x
参见 UPGRADE-3.0.md。
configureOptions()
已经在 Symfony 中使用 3.x
所以你必须替换方法名称 ;)
示例:
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'password_field' => false
]);
}
我有一个 symfony 3.4 格式 class UserForm
并且我在 setDefaultOptions
方法中设置了选项 'password_field' => false
:
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".
如文档中所述,我认为一切正常。有什么想法吗?
setDefaultOptions()
已被弃用,取而代之的是 configureOptions()
。这个方法名在 Symfony 中被使用 2.x
参见 UPGRADE-3.0.md。
configureOptions()
已经在 Symfony 中使用 3.x
所以你必须替换方法名称 ;)
示例:
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
'password_field' => false
]);
}