Php @paramconverter注释Symfony找不到App\Entity\Article对象

Php @paramconverter注释Symfony找不到App\Entity\Article对象,php,symfony,Php,Symfony,我试图在修改注释后重定向,但@paramconverter注释未找到错误App\Entity\Article对象。您知道吗​​问题出在哪里 /** * @Route("/{id}/modifier", name="comment_edit", methods={"GET","POST"}, requirements={"id" = "\d+"}) * @param Requ

我试图在修改注释后重定向,但@paramconverter注释未找到错误App\Entity\Article对象。您知道吗​​问题出在哪里

/**
 * @Route("/{id}/modifier", name="comment_edit", methods={"GET","POST"}, requirements={"id" = "\d+"})
 * @param Request $request
 * @param Article $article
 * @param Comment $comment
 * @param LinkRepository $linkRepository
 * @param MoreRepository $moreRepository
 * @return Response
 */
public function editComment(Request $request,Article $article, Comment $comment, LinkRepository $linkRepository,MoreRepository $moreRepository): Response
{
    $form = $this->createForm(CommentType::class, $comment);
    $form->handleRequest($request);
    
    if ($form->isSubmitted() && $form->isValid()) {
        $this->getDoctrine()->getManager()->flush();
        return $this->redirectToRoute('article_details',['id' => $article->getId()]);
    }
}   

使用函数名(
editComment
)时,似乎您传递的是
Comment
id
,而不是
文章的
id

在没有任何明确解释的情况下,Symfony尝试在控制器参数(一篇
文章
)中查找第一个实体的
id
(URL参数的名称),但找不到它,因为您似乎在试图修改
注释

由于您希望通过URL参数对多个对象进行水合处理,因此应明确说明如何查找每个对象:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;

/**
 * @Route("/{id_comment}/modifier", name="edit_comment")
 * @Entity("comment", expr="repository.find(id_comment)")
 * @Entity("article", expr="repository.findArticleByCommentID(id_comment)")
 */
public function editComment(Request $request, Article $article, Comment $comment, LinkRepository $linkRepository, MoreRepository $moreRepository): Response
{
    // ...
然后在
文章库中创建一个名为
findArticleByCommentID()
的函数

如果只希望通过注释找到
$comment
,还可以执行以下操作:

/**
 * @Route("/{id_comment}/modifier", name="edit_comment")
 * @Entity("comment", expr="repository.find(id_comment)")
 */
public function editComment(Request $request, Comment $comment, LinkRepository $linkRepository, MoreRepository $moreRepository): Response
{
    // Notice there isn't any Article in the controller arguments
    $article = $comment->getArticle();
    // ...

有关参数转换的更多信息,请参见:

对象文章的名称空间是什么?是否使用
导入
引用对象原点?看起来您没有导入此对象,因此它使用默认名称空间。尝试对
设备使用
import
,或在注释
@param full\class\path\Device
中使用完整的类路径。您是否有
use App\Entity\Article行?(或者无论文章实体的名称空间是什么)是的,我使用App\Entity\Article