App:ParamConverter注释使用symfony 4未找到Post对象



我想通过id或slug发布,使用ParamConverter,但我发现应用程序错误:Post object not found by the @ParamConverter annotation。我知道我是symfony的初学者,我接受了培训。

我试过路线http://127.0.0.1:8000/blog/post/1

BlogController.php

namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentRoutingAnnotationRoute;
use SensioBundleFrameworkExtraBundleConfigurationParamConverter;
use SymfonyComponentHttpFoundationRequest;
use AppEntityPost;
/**
* @Route("/blog")
*/
class BlogController extends AbstractController {
/**
* @Route("/post/{id}", requirements={ "id" : "d+" }, name="get_one_post_by_id", methods={"GET"})
* @ParamConverter("post", class="App:Post")
*/
public function postById($post){
return $this->json($post);
}
/**
* @Route("/post/{slug}", methods={"GET"})
* @ParamConverter("post", class="App:Post", options={"mapping": {"slug": "slug"}})
*/
public function postBySlug($post){
return $this->json($post);  
}
/**
* @Route("/post/{id}", name="delete-post", methods={"DELETE"})
*/
public function destroy(Post $post){
$em = $this->getDoctrine()->getManager();
$em->remove($post);
$em->flush();
return $this->json(null, 204);
}

它应该看起来像:

use AppEntityPost;
/**
* @Route("/post/{id}", requirements={ "id" : "d+" }, name="get_one_post_by_id", methods={"GET"})
*/
public function postById(Post $post){
return $this->json($post);
}

这都是

最新更新