I have a Car
entity embedded in Person
entity.
// PersonType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name')
->add('age')
->add('car',CarType::class)
;
}
// CarType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('marka',EntityType::class, array(
'class' => 'FormularzeBundle:User2','choice_label' => 'age'
))
->add('model',EntityType::class, array(
'class' => 'FormularzeBundle:Car',
'choice_value' => 'model'
))
->add('rok')
;
}
///Car entity
class Car {
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="marka", type="string", length=255)
*/
private $marka;
/**
* @var string
*
* @ORM\Column(name="model", type="string", length=255)
*/
private $model;
/**
* @var int
*
* @ORM\Column(name="rok", type="integer")
*/
private $rok;
/**
* @ORM\OneToMany(targetEntity="Person", mappedBy="car")
*/
private $persons;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set marka
*
* @param string $marka
* @return Car
*/
public function setMarka($marka) {
$this->marka = $marka;
return $this;
}
/**
* Get marka
*
* @return string
*/
public function getMarka() {
return $this->marka;
}
/**
* Set model
*
* @param string $model
* @return Car
*/
public function setModel($model) {
$this->model = $model;
return $this;
}
/**
* Get model
*
* @return string
*/
public function getModel() {
return $this->model;
}
/**
* Set rok
*
* @param integer $rok
* @return Car
*/
public function setRok($rok) {
$this->rok = $rok;
return $this;
}
/**
* Get rok
*
* @return integer
*/
public function getRok() {
return $this->rok;
}
/**
* Set person
*
* @param \FormularzeBundle\Entity\Person $person
* @return Car
*/
public function setPerson(\FormularzeBundle\Entity\Person $person = null) {
$this->person = $person;
return $this;
}
/**
* Get person
*
* @return \FormularzeBundle\Entity\Person
*/
public function getPerson() {
return $this->person;
}
/**
* Add persons
*
* @param \FormularzeBundle\Entity\Person $persons
* @return Car
*/
public function addPerson(\FormularzeBundle\Entity\Person $persons)
{
$this->persons[] = $persons;
return $this;
}
/**
* Remove persons
*
* @param \FormularzeBundle\Entity\Person $persons
*/
public function removePerson(\FormularzeBundle\Entity\Person $persons)
{
$this->persons->removeElement($persons);
}
/**
* Get persons
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPersons()
{
return $this->persons;
}
public function __toString() {
return $this->marka;
}
}
Via CarType
'model' property I would like to insert to database a value from 'model'
property of FormularzeBundle:Car
but I always insert different one (value from 'producer' property). I'm setting choice_value' => 'model'
but it is not working.
Thank you in advance for help.