Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 阶级不存在主义_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 阶级不存在主义

Php 阶级不存在主义,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,好吧,看来我自己没能力解决这个问题 我正在使用symfony和doctrine构建一个应用程序 出于某种原因,我需要在控制器中调用我的数据库,但我遇到了一个错误 每次我尝试调用此函数时: private function getAgency(string $userid) { $idAgency=$this->getDoctrine()->getRepository(User::class)->find($userid)->getidAgency(

好吧,看来我自己没能力解决这个问题

我正在使用symfony和doctrine构建一个应用程序

出于某种原因,我需要在控制器中调用我的数据库,但我遇到了一个错误

每次我尝试调用此函数时:

private function getAgency(string $userid)
    {
        $idAgency=$this->getDoctrine()->getRepository(User::class)->find($userid)->getidAgency();
        $Agency=$this->getDoctrine()->getRepository(Agency::class)->find($idAgency);
        return $Agency;
    
    }
我遇到了这个错误:
Class-App\Entity\Agency不存在
我不理解,因为Agency实体确实存在,Agency.php文件:

namespace App\Entity;


use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;


/**
 * @ORM\Entity(repositoryClass="App\Repository\AgencyRepository")
 * @UniqueEntity("nameAgency")
 */
class Agency
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="integer")
     * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="idAgency")
     */
    private $user_id;

    /**
     * @ORM\Column(type="string", length=180, unique=true)
     */
    private $nameAgency;

    /**
     * @ORM\Column(type="integer")
     */
    private $idDefaultContact;

    /**
     * @ORM\Column(type="string", nullable=true)
     * @Assert\NotBlank
     */
    private $nameContact;
    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $idContact;

    /**
     * @ORM\Column(type="string", nullable=true)
     */
    private $NameSpecialContact;
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $commentary;

    // Contructors

    public function getnameAgency(): ?string
    {
        return $this->nameAgency;
    }

    public function setnameagency(string $nameAgency)
    {
        $this->nameAgency = $nameAgency;
        return $this;
    }

    public function getnameContact(): ?string
    {
        return $this->nameContact;
    }
    public function setnameContact(string $nameContact)
    {
        $this->nameContact = $nameContact;
        return $this;
    }

    public function getcommentary(): ?string
    {
        return $this->commentary;
    }

    public function setcommentary(string $commentary)
    {
        $this->commentary = $commentary;
        return $this;
    }

}
据我所知,我以与代理实体相同的方式调用用户实体,然后删除所有代理调用;使用用户实体的部件工作得非常好

我错过了什么

编辑:正如所指出的;我使用了
use-App\Entity\User;使用App\Entity\agent


但它不起作用

可能缺少use关键字


名称空间App\Bar;
使用App\Entity\agent;
福班
{
私有函数getAgency(字符串$userid)
{
$idAgency=$this->getDoctrine()->getRepository(User::class)->find($userid)->getidAgency();
$Agency=$this->getDoctrine()->getRepository(Agency::class)->find($idAgency);
返回$Agency;
}
}

类不存在可能由3个不同点引起:

  • 类本身声明错误(命名空间或类名)
  • 调用未使用正确的use语句
  • 文件夹体系结构与声明的命名空间不匹配

  • 正如您所指出的,1和2似乎不适用于您的情况。你能检查一下3吗?

    你应该使用关键字你的意思是什么?代理对象无论你在哪里调用或显示
    私有函数getAgency(字符串$userid){$idAgency=$this->getDoctrine()->getRepository(用户::类)->find($userid)->getidAgency();$Agency=$this->getDoctrine()->getRepository(代理::类)->find($idAgency)return$Agency;}
    可能没有
    使用
    关键字您的意思是这样的吗?``使用App\Entity\User;使用App\Entity\Agency;`我肯定会利用;但它也不起作用……不,他们在场;不要在原始帖子中说类似于你的问题的链接可能对你有帮助OK,你的链接没有帮助;我试图找到一个地方,在那里我可以错误地说出我的代理对象,但可以找到任何。。。然而,这个类肯定存在,VS代码检测到我的getRepository(Agency::class)作为对这个类的调用,这可能是有效的。。。。My Agency.php文件位于Entity\InfluenceurManagement\Agency.php下,User.php位于Entity\User.php下。。。。如何保持此文件夹的组织并使其正常工作?如果您有Entity/InfluenceurManagement/Agency.php,那么Agency.php的名称空间应该是Entity/InfluenceurManagement,而对于Entity/User.php,它应该是唯一的Entity更改名称空间似乎没有解决我的问题,但是将文件移动到Entity文件夹(InfluenceurManagement之外)似乎解决了这个问题