gpt4 book ai didi

php - Symfony Doctrine DQL 在实体管理器中找不到 createQuery

转载 作者:搜寻专家 更新时间:2023-10-31 20:58:28 25 4
gpt4 key购买 nike

我使用 Symfony 学习网络开发已有一段时间了。我正在关注 Symfony 的 website 教程。和 Doctrine tutorial ,并尝试在 Doctrine ORM 中使用实体管理器来创建查询,但 PhpStorm 的自动完成功能告诉我它找不到 createquery()。 (截图见下方)

enter image description here

enter image description here

最佳答案

根据您的屏幕截图(getRepository, flush, persist...)$this->getDoctrine()->getManager() 的方法,您可以在任何 symfony controller 类中找到:

enter image description here

您要使用的是 $this->getEntityManager()->createQuery(),您可以在 symfony repository 类中找到它:

enter image description here

所以正确的做法是创建一个存储库并将你的方法添加到其中,然后在你的 Controller 中使用这个方法:

class UserController extends Controller
{

/**
* @Route("/", name="user_list")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$userrs = $em->getRepository("AppBundle:User")->myRepositoryMethod();
...

关于php - Symfony Doctrine DQL 在实体管理器中找不到 createQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50013852/

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