getDoctrine()->getRepository('testBundle:test'); $pot-6ren">
gpt4 book ai didi

php - symfony 2 - 尝试调用类 "findBy"的名为 "testBundle\Entity\test"的未定义方法

转载 作者:行者123 更新时间:2023-12-01 22:22:40 27 4
gpt4 key购买 nike

我无法从数据库中获取数据。这是代码:

$testRepository= $this->getDoctrine()->getRepository('testBundle:test');
$potds = $testRepository->findBy(
array(),
);

这是实体类:

 * @ORM\Table()
* @ORM\Entity(repositoryClass="testBundle\Entity\test")
* @ORM\HasLifecycleCallbacks
*/
class test
{ /* ... */ }

这是存储库的代码:

namespace testBundle\Entity;

/**
* TestRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class testRepository extends \Doctrine\ORM\EntityRepository
{
}

我收到此错误消息:symfony 2 - 尝试调用类“testBundle\Entity\test”中名为“findBy”的未定义方法

用 Doctrine 插入数据是可行的,所以 Entity 应该一切正常。

最佳答案

您的存储库类定义不正确:

@ORM\Entity(repositoryClass="testBundle\Entity\test")

应该是:

@ORM\Entity(repositoryClass="testBundle\Entity\testRepository")

现在这段代码:

$testRepository= $this->getDoctrine()->getRepository('testBundle:test');

正在返回实体类,而不是存储库。

关于php - symfony 2 - 尝试调用类 "findBy"的名为 "testBundle\Entity\test"的未定义方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38991874/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com