Symfony 5 object not found by the @ParamConverter annotation

I’m using Symfony 5 and Doctrine 2.

When I use the ajax call below described I get this error :

AppEntityCalendar object not found by the @ParamConverter
annotation.

However, I don’t use parameter for my route.

There is my ajax function :

    var url = Routing.generate('calendar.ajaxEditEvent');

    $.ajax({
    type: "POST",
    url: url,
    data: {

            title: e.event.title,
            description: e.event.extendedProps.description,
            start: e.event.start,
            end: e.event.end,
            backgroundColor: e.event.backgroundColor,
            borderColor: e.event.borderColor,
            textColor: e.event.textColor,
            allDay: e.event.allDay,
            calendarId: e.event.id

          }
    ,  
    dataType: 'json',  
    async: true,
    sucess: function(reponse){

        console.log('success');
        console.log(response);

    },  
    error : function(response) {  

        console.log('error');
        console.log(response);  

    }

});

And my calling function in my controller :

/**
 * @Route("/ajaxEditEvent", options={"expose"=true}, name="calendar.ajaxEditEvent", methods={"POST"})
 *
 * @param CalendarRepository $calendarRepository
 * @param Request $request
 * @param EntityManagerInterface $manager
 * 
 * @return Response
 */
public function ajaxEditEvent(CalendarRepository $calendarRepository, Request $request, EntityManagerInterface $manager): Response
{
    
    $title = $request->get('title');
    $description = $request->query->get('description');
    $start = $request->query->get('start');
    $end = $request->query->get('end');
    $backgroundColor = $request->query->get('backgroundColor');
    $borderColor = $request->query->get('borderColor');
    $textColor = $request->query->get('textColor');
    $allDay = $request->query->get('allDay');
    $calendarId = $request->query->get('calendarId');

    if(
        !empty($title) &&
        !empty($description) &&
        !empty($start) &&
        !empty($backgroundColor) &&
        !empty($borderColor) &&
        !empty($textColor)
      ) 
    {
       
        $code = 200;
        $message = '';

        if(empty($calendarId))
        {

            $calendar = new Calendar;
            $code = 201;

        }
        else
        {

            $calendar = $calendarRepository->find($calendarId);

        }

        $calendar->setTitle($title);
        $calendar->setDescription($description);
        $calendar->setStart(new DateTime($start));

        if($allDay)
        {

            $calendar->setEnd(new DateTime($start));

        }
        else
        {
                               
            $calendar->setEnd(new DateTime($end));

        }

        $calendar->setAllDay($allDay);
        $calendar->setBackgroundColor($backgroundColor);
        $calendar->setBorderColor($borderColor);
        $calendar->setTextColor($textColor);

        $manager->persist($calendar);
        $manager->flush();

        $message = 'OK';

    }
    else
    {

        //return new Response('Incomplete data', 404);
        $code = 404;
        $message = 'Incomplete data';

    }

    return new Response($message, $code);
}

I don’t understand where @ParamConverter is used.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *