У меня проблема с моим проектом. У меня есть форма для регистрации, где я просто спрашиваю lastName, firstName, Email и пароль. Когда пользователь входит в систему, я хочу запросить дополнительную информацию, такую как адрес, город, почтовый индекс, birthDate и phoneNumbre, но я не знаю, нужно ли мне для этого просто использовать второй тип или использовать его в качестве регистрации.
моя сущность
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class FosUser implements UserInterface
{
const ROLES = [
'ROLE_USER',
'ROLE_MODERATOR',
'ROLE_ADMIN',
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="text")
*/
private $password;
/**
* @var string
*/
private $plainPassword;
/**
* @var array $roles
* @ORM\Column(type="array")
*/
private $roles = ['ROLE_USER'];
/**
* @ORM\Column(type="date")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Ideas", mappedBy="userId")
*/
private $Idea;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updateAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $zipCode;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $birthDate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $phoneNumber;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->Idea = new ArrayCollection();
}
/**
* @see UserInterface
*/
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @return array (Role|string)[] The user roles
*/
public function getRoles() :array
{
return $this->roles;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getSalt()
{
return null;
}
/**
* @return string The username
*/
public function getUsername()
{
return (string)$this->email;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
$this->plainPassword = null;
return $this;
}
/**
* @return Collection|Ideas[]
*/
public function getIdea(): Collection
{
return $this->Idea;
}
public function addIdea(Ideas $idea): self
{
if (!$this->Idea->contains($idea)) {
$this->Idea[] = $idea;
$idea->setUserId($this);
}
return $this;
}
public function removeIdea(Ideas $idea): self
{
if ($this->Idea->contains($idea)) {
$this->Idea->removeElement($idea);
// set the owning side to null (unless already changed)
if ($idea->getUserId() === $this) {
$idea->setUserId(null);
}
}
return $this;
}
public function getUpdateAt(): ?\DateTimeInterface
{
return $this->updateAt;
}
public function setUpdateAt(?\DateTimeInterface $updateAt): self
{
$this->updateAt = $updateAt;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getZipCode(): ?int
{
return $this->zipCode;
}
public function setZipCode(?int $zipCode): self
{
$this->zipCode = $zipCode;
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeInterface $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
public function getPhoneNumber(): ?int
{
return $this->phoneNumber;
}
public function setPhoneNumber(?int $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
}
мой тип регистрации и тот же для полной информации
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName')
->add('lastName')
->add('birthDate')
->add('email')
->add('phoneNumber')
->add('password', RepeatedType::class,
[
'type' => PasswordType::class,
'invalid_message' => 'Les deux mots de passe doivent etre identique.',
'required' => true,
'first_options' =>
[
'label' => 'Mot de passe',
'label_attr' => ['class' => 'w-100']
],
'second_options' =>
[
'label' => 'Confirmation',
'label_attr' => ['class' => 'w-100']
]
])
->add('submit', SubmitType::class, [
'attr' => ['class' => 'btn btn-primary'],
'label' => 'Soumettre'
])
->add('address')
->add('city')
->add('zipCode');
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => FosUser::class,
]);
}
}
что мне нужно сделать? Спасибо и извините за мой английский sh не идеально