我正在尝试从多实体表单中保留数据。
这是 ClearType
<?php
namespace IS\ClearBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class ClearType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('date','date', array(
'input' => 'datetime',
'widget' => 'choice',
))
->add('urlStatus', 'choice',array('choices' => array('Done' => 'Done','Not Done' => 'Not Done'),'required' => false))
->add('applicationStatus', 'choice',array('choices' => array('Done' => 'Done','Not Done' => 'Not Done'),'required' => false))
->add('project','entity',array('class'=>'IS\ClearBundle\Entity\Project', 'property'=>'name'))
;
}
这里是控制器:
public function updateAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$entity = $em->getRepository('ISClearBundle:Clearance')->find($id);
$project = $em->getRepository('ISClearBundle:Project')->find($entity->getProjectId());
if (!$entity) {
throw $this->createNotFoundException('Unable to find Clear entity.');
}
$editForm = $this->createForm(new ClearType(), $entity);
$deleteForm = $this->createDeleteForm($id);
$request = $this->getRequest();
$editForm->bindRequest($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('clear_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
项目在 Clear 实体中被引用:
<?php
namespace IS\ClearBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* IS\ClearBundle\Entity\Clear
*/
class Clear
{
/**
* @var datetime $date
*/
private $date;
/**
* @var string $urlStatus
*/
private $urlStatus;
/**
* @var string $applicationStatus
*/
private $applicationStatus;
/**
* @var string $ipStatus
*/
private $ipStatus;
/**
* @var string $totalStatus
*/
private $totalStatus;
/**
* @var integer $id
*/
private $id;
/**
* @var IS\ClearBundle\Entity\Project
*/
private $project;
我不知道如何在表单中保留项目 ID。
谢谢你的帮助!