how can I save the data from my created form , which is using 2 entitys to output different select and input fields, into the table of the first entity.
Main Entity is Tasks.php - in this form I get also data from 2 other Entities called TaskTypes and User.
It looks like this:
$AddTask = new Tasks();
$form = $this->createFormBuilder($AddTask)
->add('task_title', 'text', array('label' => 'Aufgabentitel', 'attr' => array('class' => 'first')))
->add('task_description', 'textarea', array('label' => 'Aufgabenbeschreibung'))
->add('task_types', 'entity', array(
'class' => 'SeotoolMainBundle:TaskTypes',
'property' => 'task_type_title',
'label' => 'Aufgabentyp'))
->add('user', 'entity', array(
'class' => 'SeotoolMainBundle:User',
'property' => 'username',
'label' => 'Kundenzuordnung',
'query_builder' => function(EntityRepository $er ) use ( $request ) {
return $er->createQueryBuilder('w')
->orderBy('w.username', 'ASC')
->where('w.isAdmin = 0')
->andWhere('w.isActive = 1');
}
))
->add('Aufgabe anlegen', 'submit')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$task = new Tasks();
$task->setTaskTitle($request->request->get('form')['task_title']);
$task->setTaskDescription($request->request->get('form')['task_description']);
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$em->flush();
return $this->redirect($this->generateUrl('add_task'));
}
My Entity/Tasks.php looks like this:
...
/**
* @Assert\Type(type="Seotool\MainBundle\Entity\TaskTypes")
*/
protected $tasktypes;
/**
* @Assert\Type(type="Seotool\MainBundle\Entity\User")
*/
protected $user;
...
public function getTaskTypes()
{
return $this->tasktypes;
}
public function setTaskTypes(TaskTypes $tasktypes = null)
{
$this->tasktypes = $tasktypes;
}
public function getUser()
{
return $this->user;
}
public function setUser(User $user = null)
{
$this->user = $user;
}
I got these code snippets out of an example how to make forms with multiple entities. But I don't get it working to save the data from the "extern entity" in the table of the "main entity"
What I tried:
...
/**
* @Assert\Type(type="Seotool\MainBundle\Entity\TaskTypes")
* @ORM\Column(type="integer")
*/
protected $tasktypes;
/**
* @Assert\Type(type="Seotool\MainBundle\Entity\User")
* @ORM\Column(type="string")
*/
protected $user;
....
public function getTaskTypes()
{
return $this->tasktypes;
}
public function setTaskTypes()
{
return $this->tasktypes;
}
public function getUser()
{
return $this->user;
}
public function setUser(User $user = null)
{
$this->user = $user;
}
It outputs following error:
Neither the property "task_types" nor one of the methods "addTaskTyp()"/"removeTaskTyp()", "addTaskType()"/"removeTaskType()", "setTaskTypes()", "taskTypes()", "__set()" or "__call()" exist and have public access in class "Seotool\MainBundle\Entity\Tasks". 500 Internal Server Error - NoSuchPropertyException