我创建了一个symfony API应用程序,当我尝试执行我的控制器的listAction()请求时,我在postman中有一个错误500:
" message":"需要通过setController设置控制器和方法。",
我在邮差中执行:
我使用JMSSerializer和FOSRestBundle
我的控制器:
/**
* @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);
}
我的实体:
<?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;
}
}
感谢您的帮助。