我有2个实体:person和emailaddress
class Person
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var Emailaddress[]
* @ORM\OneToMany(targetEntity="Emailaddress", mappedBy="person", cascade={"ALL"})
*
*/
private $emails;
public function __construct() {
$this->emails = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Person
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Add email
*
* @param \AppBundle\Entity\Emailaddress $email
*
* @return Person
*/
public function addEmail(\AppBundle\Entity\Emailaddress $email)
{
$this->emails[] = $email;
$email->setPerson($this);
return $this;
}
/**
* Remove email
*
* @param \AppBundle\Entity\Emailaddress $email
*/
public function removeEmail(\AppBundle\Entity\Emailaddress $email)
{
$this->emails->removeElement($email);
}
/**
* Get emails
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getEmails()
{
return $this->emails;
}
}
class Emailaddress
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="emailaddress", type="string", length=100)
*/
private $emailaddress;
/**
* @var Person
* @ORM\ManyToOne(targetEntity="Person", inversedBy="emails")
* @ORM\JoinColumn(name="person_id", referencedColumnName="id")
*/
private $person;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set emailaddress
*
* @param string $emailaddress
*
* @return Emailaddress
*/
public function setEmailaddress($emailaddress)
{
$this->emailaddress = $emailaddress;
return $this;
}
/**
* Get emailaddress
*
* @return string
*/
public function getEmailaddress()
{
return $this->emailaddress;
}
/**
* Set person
*
* @param \AppBundle\Entity\Person $person
*
* @return Emailaddress
*/
public function setPerson(\AppBundle\Entity\Person $person = null)
{
$this->person = $person;
return $this;
}
/**
* Get person
*
* @return \AppBundle\Entity\Person
*/
public function getPerson()
{
return $this->person;
}
}
在EmailaddressType中我有:
$builder->add('email');
在PersonType中:
$builder->add('name')
->add('emails', CollectionType::class, array(
'entry_type' => EmailAddressType::class,
'allow_add' => true,
));
现在,当在电子邮件字段上生成表单时,不会显示任何内容。 如何生成电子邮件字段?
由于