Я переопределил FOS RegistrationFormType вот так
<?php
namespace AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseRegistrationFormType;
class RegistrationType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('tel')
->add('sexe')
->add('date_naiss')
->add('ville')
->add('prenom')
->add('nom')
->add('taille')
->add('poids')
->add('player_id')
->add('panier')
->add('pp')
->add('coupons');
}
public function getParent()
{
return BaseRegistrationFormType::class;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'app_user_registration';
}
}
Я настроил service.yml вот так
app.form.registration:
class: AdminBundle\Form\RegistrationType
tags:
- { name: form.type, alias: app_user_registration }
И fosuserbundle для использования моего типа формы вот так
registration:
form:
type: AdminBundle\Form\RegistrationType
но когда я использую форму, подобную этой
{{ form_start(form, {'attr': {'class': 'needs-validation'}}) }}
<div class="form-group">
{# Génération du label. #}
{{ form_label(form.nom, "Votre Nom") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.nom) }}
{# Génération de l'input. #}
{{ form_widget(form.nom, {'attr': {'class': 'nom'}}) }}
<div class="err" id="name-invalid-feedback"></div>
</div>
<div class="form-group">
{# Génération du label. #}
{{ form_label(form.prenom, "Votre Prenom") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.prenom) }}
{# Génération de l'input. #}
{{ form_widget(form.prenom, {'attr': {'class': 'nom'}}) }}
<div class="err" id="name-invalid-feedback"></div>
</div>
<div class="form-group">
{# Génération du label. #}
{{ form_label(form.email, "adresse mail") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.email) }}
{# Génération de l'input. #}
{{ form_widget(form.email, {'attr': {'class': 'email'}}) }}
<div class="err" id="email-invalid-feedback"></div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
{# Génération du label. #}
{{ form_label(form.ville, "Ville") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.ville) }}
{# Génération de l'input. #}
{{ form_widget(form.ville, {'attr': {'class': 'ville'}}) }}
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
{# Génération du label. #}
{{ form_label(form.tel, "Numéro de téléphone") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.tel) }}
{# Génération de l'input. #}
<div class="row">
<div class="col-md-2 col-xs-2" style="padding: 0px;margin-left: 10px;margin-right: -10px">
<input value="+ 237" readonly="readonly" class="form-control">
</div>
<div class="col-xs-10 col-md-10">
{{ form_widget(form.tel, {'attr': {'class': 'tel'}}) }}
<div class="err" id="tel-invalid-feedback"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
{# Génération du label. #}
{{ form_label(form.plainPassword.first, "Mot de passe") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.plainPassword.first) }}
{# Génération de l'input. #}
{{ form_widget(form.plainPassword.first, {'attr': {'class': 'mdp'}}) }}
<div class="err" id="mdp-invalid-feedback"></div>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">
{# Génération du label. #}
{{ form_label(form.plainPassword.second, "Confirmation") }}
{# Affichage des erreurs pour ce champ précis. #}
{{ form_errors(form.plainPassword.second) }}
{# Génération de l'input. #}
{{ form_widget(form.plainPassword.second, {'attr': {'class': 'conf'}}) }}
<div class="err" id="conf-invalid-feedback"></div>
</div>
</div>
{{ form_end(form) }}
, но у меня есть эта ошибка
Ни свойство "nom", ни один методов "nom ()", "getprenom ()" / "isnom ()" / "hasnom ()" или "__call ()" существуют и имеют доступ publi c в классе "Symfony \ Component \ Form \ FormView ".
и это мой контроллер регистра
public function registerAction(Request $request)
{
/** @var $formFactory FactoryInterface */
$formFactory = $this->get('fos_user.registration.form.factory');
/** @var $userManager UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$user = $userManager->createUser();
$user->setEnabled(true);
$user->addRole('ROLE_CLIENT');
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$form = $formFactory->createForm();
$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->generateUrl('user_registration_confirmed');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE, $event);
if (null !== $response = $event->getResponse()) {
return $response;
}
}
return $this->render(
'@App/Registration/register.html.twig', array(
'form' => $form->createView(),)
);
}
Надеюсь, мне помогут