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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)