我有一个用于 Symfony 请求的 createAction。
如何通过创建新的实体值在另一个实体中添加一些值。
请参阅以下 foreach 部分;它出什么问题了?
public function createAction(Request $request)
{
$entity = new FooType();
$form = $this->createForm(new FooTypeType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
$entities = $em->getRepository('OtherBundle:Lists')->findAll();
foreach($entities as $list){
$manager = $this->getDoctrine()->getManager();
$listValue = new ListValue();
$listValue->setSpecification( new ListsType(), $list );
$manager->persist($listValue);
$manager->flush();
}
return $this->redirect($this->generateUrl('foo_foobar_show', array('id' => $entity->getId())));
}