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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答