2016-04-28 5 views
0

Ich las mehrere Lösungen für diesen Fehler, aber es funktioniert nicht, ich weiß nicht genau, wo das Problem ist, weil andere Erhaltungs-Anforderungs- funktioniert mein Formulartyp wie folgt:Hinweis: Array String-Konvertierung 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)); 
} 

und die Funktion der Steuerung ist wie folgt:

 /** 
* @ApiDoc(description="Associate photo with tags.") 
* 
* @ParamConverter("photo", class="TestTaskPhotosBundle:Photo") 
* 
* @Rest\Post("/photos/{id}/tags") 
* @Rest\RequestParam(name="tags", requirements=".+", nullable=false, map=true, description="Tags that associates photo.") 
* @Rest\View() 
*/ 
public function postTagsToPhotoAction(Photo $photo, array $tags) 
{ 
    $em = $this->getDoctrine()->getManager(); 

    //TODO: add validation and maybe form 

    if ($tags) { 
     $tags = $em->getRepository('TestTaskTagsBundle:Tag')->findOrCreateByTitles($tags); 
    } 

    foreach ($tags as $tag) { 
     $photo->addTag($tag); 
    } 

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

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

Antwort

1

gelöst, das Problem war in cotroller Funktion, die Lösung wird wie folgt:

 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

Hallo @Nada können Sie bitte fügen Sie Ihren Code, was Sie geändert haben, um das Problem zu lösen, so dass andere in der Lage sein werden, Ihre Lösung zu beziehen, und könnte Hilfe bekommen. –

+0

Okey mit Vergnügen .. fertig – Nada