1

I made a symfony API application and when I try to execute the listAction () request of my controller I have an error 500 in postman:

"message": "Controller and method needs to be set via setController.",

My execution in postman:

Error postman

I use JMSSerializer and FOSRestBundle

My controller:

/**
 * @Rest\Get("/articles", name="app_article_list")
 * @Rest\QueryParam(
 *     name="keyword",
 *     requirements="[a-zA-Z0-9]",
 *     nullable=true,
 *     description="The keyword to search for."
 * )
 * @Rest\QueryParam(
 *     name="order",
 *     requirements="asc|desc",
 *     default="asc",
 *     description="Sort order (asc or desc)"
 * )
 * @Rest\QueryParam(
 *     name="limit",
 *     requirements="\d+",
 *     default="15",
 *     description="Max number of movies per page."
 * )
 * @Rest\QueryParam(
 *     name="offset",
 *     requirements="\d+",
 *     default="0",
 *     description="The pagination offset"
 * )
 * @Rest\View()
 */
public function listAction(ParamFetcherInterface $paramFetcher)
{
    $pager = $this->getDoctrine()->getRepository(Article::class)->search(
        $paramFetcher->get('keyword'),
        $paramFetcher->get('order'),
        $paramFetcher->get('limit'),
        $paramFetcher->get('offset')
    );

    return new Articles($pager);
}

My Entity:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Class Article
 * @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
 * @ORM\Table(name="article")
 *
 * @Serializer\ExclusionPolicy("all")
 */
class Article
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue()
     *
     * @Serializer\Expose()
     */
    private $id;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotBlank(groups={"Create"})
     * @Serializer\Expose()
     */
    private $title;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotBlank(groups={"Create"})
     * @Serializer\Expose()
     */
    private $content;

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id): void
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param mixed $title
     */
    public function setTitle($title): void
    {
        $this->title = $title;
    }

    /**
     * @return mixed
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * @param mixed $content
     */
    public function setContent($content): void
    {
        $this->content = $content;
    }
}

Thank you for help.

0 Answers0