2016-04-28 88 views
0

我读了这个错误的几种解决方案,但它不工作,我不知道究竟哪里出了问题,因为其他GET请求工作 我formType如下:注意:数组字符串转换Symfony2的

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    $builder 
     ->add('image', null, array('property_path' => 'file')) 
     ->add('tags', null, array('mapped' => false)) 
     ->add('machinetags', null, array('mapped' => false)); 
} 

和控制器的功能如下:

​​

回答

1

解决,这个问题是在cotroller功能,将溶液如下:

 public function postMachinetagsToPhotoAction($id, array $machinetags) 
{ 
    $em = $this->getDoctrine()->getManager(); 

    //TODO: add validation and maybe form 
    $photo = $em->getRepository('TestTaskPhotosBundle:Photo')->find($id); 
    if ($machinetags) { 
     $machinetags = $em->getRepository('TestTaskMachineTagsBundle:MachineTag')->findOrCreateByTitles($machinetags); 
    } 

    foreach ($machinetags as $machinetag) { 
     $photo->addMachineTag($machinetag); 
    } 

    $em->persist($photo); 
    $em->flush(); 

    return array('photo' => $photo); 
} 
+1

Hi @Nada您好,您可以请添加您的代码,您已更改以解决问题,以便其他人可以引用您的解决方案,并可能获得帮助。 –

+0

快乐的Okey ..做到了 – Nada