我希望覆盖FOSUserBundle的RegistrationType表单,但在registration_content.html.twig模板中遇到了这个错误:
在类“Symfony\Component\Form\FormView”中,既没有属性“firstname”,也没有方法“firstname()”、“getfirstname()”/“isfirstname()”/“hasfirstname()”或“__call()”存在且具有公共访问权限。
这是我的RegistrationType表单:
class RegistrationType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('firstname');
}
public function getParent() {
return 'fos_user_registration';
}
public function getName() {
return 'app_user_registration';
}
}
fos_user.yaml:
fos_user:
registration:
confirmation:
enabled: true
form:
name: app_user_registration
db_driver: orm
user_class: App\Entity\User
firewall_name: main
from_email:
address: foo@example.com
sender_name: bar@example.com
用户实体:
class User extends BaseUser {
//
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
protected $firstname;
}
registration_content.html.twig:
{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register', 'id': 'form-sign-up'}}) }}
<div class="form-group form-group--float form-group--centered">
{{ form_widget(form.firstname, {'attr': {'class': 'form-control'}}) }}
<label>{{ 'firstname'|trans }}</label>
<i class="form-group__bar"></i>
</div>
{{ form_end(form) }}
在我的配置服务中,我已经放置了以下内容:
app.form.registration:
class: App\Form\RegistrationType
tags:
- { name: form.type, alias: app_user_registration }
User
类包含在问题中时削减了多少内容,但是您是否为其他属性添加了getter和setter?由于$firstname
是受保护的,因此您需要有一个getFirstname
和一个setFirstname
方法。 - dlondero