dongzhi4073 2017-05-18 02: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 02: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 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
  • ¥15 IEC61850 客户端和服务端的通讯机制
  • ¥15 MAX98357a(关键词-播放音频)
  • ¥15 Linux误删文件,请求帮助
  • ¥15 IBMP550小型机使用串口登录操作系统
  • ¥15 关于#python#的问题:现已知七自由度机器人的DH参数,利用DH参数求解机器人的逆运动学解目前使用的PSO算法
  • ¥15 发那科机器人与设备通讯配置