dongzhi4073 2017-05-18 10:08
浏览 25
已采纳

Symfony 3.2 Doctrine2以类的形式存储复杂查询的ORM

Kind time of the day, connoisseurs Symfony Already the third day I study Symfony 3.2 I learned to access several databases and tried a little Doctrine 2

Everything worked out. Prompt please where to me to store a library of requests to a database that I did not have to use repeated requests in various controllers.

If I do not understand explain

There is a controller for example this src / ParserBundle / EmployeesController.php

There is a:

$Repository = $this->getDoctrine()->getRepository('ParserBundle:Provider');
$Providers = $repository->findAll();

There is a class on queries to the database for example this src / ParserBundle / Entity / Provider.php

Then how to make complex queries I can read from the Doctrine 2 documentation, but where can I store them that would not duplicate? And how to access them from the main controllers - is there documentation about this?

  • 写回答

1条回答 默认 最新

  • douwen1901 2017-05-18 10:14
    关注

    It's called a Doctrine repository, yes there is documentation about it of course: http://symfony.com/doc/current/doctrine/repository.html

    In the controller, you call it the same way as you did before. Your custom repository class will just override the default one.

    $providers = $repository->myCustomFind();
    

    PS: Symfony is written with a f not ph... :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀