0

I read several solutions for this error but it's not working, i dont know exactly where is the problem, because other get request works my formType is as follows:

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));
}

and function of controller is as follows:

      /**
 * @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);
}
0

1 Answer 1

1

solved, the problem was in cotroller function, the solution is as follows:

        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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Nada can you please add your code that what you have changed to solve problem so others will be able to refer you solution, and might get help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.