bitte ich brauche deine Hilfe, ich versuche, ein Bild mit Nelmio-Bundle aber einzufügen es gibt mir diesen Fehler Parameter-Tags Wert '' verletzt eine Einschränkung (Erwartetes Argument vom Typ \ "Array oder Travers \", \ "string \" genannt)“Parameter Tags Wert '' verletzt eine Einschränkung (Erwartete Argument vom Typ "Array oder Traversable ", "String " gegeben) "
mein Controller wie folgt
/**
* @ApiDoc(description="Uploads photo with tags.")
*
* @Rest\FileParam(name="image", image=true, description="Image to upload.")
* @Rest\RequestParam(name="tags", requirements=".+", nullable=false, map=true, description="Tags that associates photo.")
* @Rest\View()
*/
public function postPhotoAction(ParamFetcher $paramFetcher, array $tags)
{
$em = $this->getDoctrine()->getManager();
$photo = new Photo();
$form = $this->createForm(new PhotoType, $photo);
if ($tags) {
$tags = $em->getRepository('TestTaskTagsBundle:Tag')->findOrCreateByTitles($tags);
}
$form->submit($paramFetcher->all());
if (!$form->isValid()) {
return $form->getErrors();
}
foreach ($tags as $tag) {
$photo->addTag($tag);
}
$em->persist($photo);
$em->flush();
return array('photo' => $photo);
}
wie man das bitte lösen
sicher, dass $ tags wirklich ein Array ist? Wie sieht Ihre findOrCreateByTitles-Funktion aus? – LBA
Tags ist ein Array in der Entity-Klasse/** * @ORM \ OneToMany (targetEntity = "PhotoTag", mappedBy = "Foto", cascade = {"persist"}, orphanRemoval = true) * * @var ArrayCollection | PhotoTag [] */ private $ photoTags; – Nada
findOrCreateByTitles Funktion ist eine andere Sache – Nada