Php 我使用DQL进行了自定义查询,但对象没有看到该方法

Php 我使用DQL进行了自定义查询,但对象没有看到该方法,php,symfony,oop,doctrine,dql,Php,Symfony,Oop,Doctrine,Dql,当我学习Symfony时,我在DQL中遇到了一个自定义查询问题,有一个指向文档的链接: 我做了如下相同的函数: <?php namespace App\Repository; use App\Entity\CatPost; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Symfony\Bridge\Doctrine\RegistryInterface; /** * @method

当我学习Symfony时,我在DQL中遇到了一个自定义查询问题,有一个指向文档的链接: 我做了如下相同的函数:

<?php

namespace App\Repository;

use App\Entity\CatPost;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method CatPost|null find($id, $lockMode = null, $lockVersion = null)
 * @method CatPost|null findOneBy(array $criteria, array $orderBy = null)
 * @method CatPost[]    findAll()
 * @method CatPost[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class CatPostRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, CatPost::class);
    }

    public function findAllCategoriesConnectedToPost($id) :array
    {
        $entityManager = $this->getEntityManager();

        $query = $entityManager->createQuery(
            'SELECT cat.id_cat 
             FROM App\Entity\CatPost cat 
             WHERE cat.id_post = :idPost'
        );
        $query->setParameter('idPost', $id);

        return $query->execute();
    }
}
结果,我得到了空数组,PhpStorm告诉我找不到该方法
您是否知道如何修复它?

您是否确保链接到实体中的存储库

/**
* CatPost
*
* @ORM\Entity(repositoryClass="App\Repository\CatPostRepository")
*/
class CatPost

您可以在同一文档页面上进一步看到这一点-

您可以向我们展示CatPost类的代码吗?您应该将您的完整实体和控制器的完整操作发布给我,看起来不错。尝试在你的控制器中添加var_dump$id和$id都可以,因为我从url/article/edit/{id}获得它。你应该发布你控制器的完整方法,我链接了它,如果你现在可以检查,请,我添加了我的存储库的完整文件和entity@OskarG它说缺少什么方法?在\Doctrine\Common\Persistence\ObjectRepository less中找不到方法“findAllCategoriesConnectedToPost”。。。在subject类中找不到Ctrl+F1引用的方法。来自phpstormok的完整msg,有几个原因导致这个警告,所以我们现在可以忽略它。当sql出现问题时,一个好办法是简化查询,看看是否有效。尝试以另一种方式引用该表,从cat_posts中选择*,其中id_post=:idPost假设您的数据库名为cat_posts
/App/Controller/ArticleController

$categories = $this->getDoctrine()
->getRepository(CatPost::class)
->findAllCategoriesConnectedToPost($id);

var_dump($categories);
die();
/**
* CatPost
*
* @ORM\Entity(repositoryClass="App\Repository\CatPostRepository")
*/
class CatPost