主义2基本代理,存储库 [英] Doctrine2 basic; Proxies, Repositories

查看:94
本文介绍了主义2基本代理,存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Doctrine2,它可以工作。但我真的不明白我在做什么..


  1. 我不明白什么是代理,我已经创建了em全部从命令行,但我真的需要他们吗?


  2. Doctrine2注释如何工作? Doctrne2文件是否每次扫描以从Entity注释中找到存储库类文件?


我想我需要一些资源了解ORM的基本功能..
项目正在工作,但我不太确定这是正常工作,因为它应该是..



谢谢


解决方案

首先要理解的是,你的数据库表和关系被映射到你的php实体。例如,您可能有一个用户表。然后,您将有一个代表用户实体的php类。在这个类内部是保护/私有成员变量,它们表示用户表中的值和与其他实体的关系。



Doctrine从映射文件中获取映射信息。这些可能是实体本身,其中映射信息在您的实体类中被表示为注释(注释)。您也可以使用YAML或XML将映射信息与实体类完全分离。



一旦您将Entity类和映射信息配置好并准备就绪,Doctrine,幕后产生代理类。您不必创建这些,因为您可以配置D2为您自动创建它们。代理类通过继承提供对您的实体的访问,并且是Doctrine 2的必需部分,没有它们,您不能访问实体数据。



另一件要记住的是工作单位。当您从数据库获取实体时,说用户,工作单元(uow)在内部持有对它的引用。如果然后对实体进行更改并持久刷新,则uow计算从db获取的数据与其返回的差异,并计算完成作业所需的sql。



首先可以使用D2来威胁使用D2,因为它是第一版的完全重写,并且有许多新的设计模式要理解,所以不要担心,如果你不确定现在,继续使用它,它最终将开始点击。



编辑



要回答您的第二个问题,是Doctrine扫描每个请求的映射信息。这显然会减慢执行速度。但是,在生产中,您将使用其中一个驱动程序(ApcCache,MemcachCache等)启用元数据缓存。这不会成为一个问题。还要指出,D2支持3种缓存,元数据,查询(DQL转换)和结果(数据库结果缓存)。所有这些都可以配置不同的缓存驱动程序。


I can use Doctrine2 and it works. But i really dont understand what i am doing..

  1. I don't understand what are proxies, i have created em all from command line, but do i really need them ?

  2. How Doctrine2 annotations work? Does Doctrne2 file scan every time to find the repository class file from the Entity annotation ?

i think i need some resources to understand the basic consepts of the ORM.. Project is working but i am not so sure that is working as it should be..

Thanks

解决方案

Ok, first thing to understand is that your database tables and relationships are 'mapped' to your php 'entities'. For example, you may have a users table. You will then have a php class that represents the users entity. Inside this class are protected/private member variables that represent values in your users table and relationships to other entities.

Doctrine gets the mapping information from your mapping files. These may be the entities themselves where the mapping information is represented as annotations (comments) in your entity classes. You can alternatively separate the mapping information from your entity classes altogether by using YAML or XML.

Once you have your Entity classes and mapping information configured and ready to go, Doctrine, behind the scenes produces 'Proxy' classes. You don't have to create these as you can configure D2 to create them automatically for you. The proxy classes provide access to your entities via inheritance and are a required part of Doctrine 2, without them, you could not access entity data.

The other thing to remember is the unit of work. When you get an entity from the db, say a user, the unit of work (uow) holds a reference to it internally. If you then make changes to the entity and persist and flush it, the uow calculates the difference between the one it got from the db and the one it is returning and calculate the sql needed to complete the job.

It can be intimidating to work with D2 at first as it is a complete rewrite of the 1st version and there are many new design patterns to understand so don't' worry if you're not sure of it now, keep working with it and it will eventually start clicking.

EDIT

To answer your second question, yes Doctrine scans your mapping information on every request. This will obviously slow down execution. However, in production you would enable metadata caching using one of the drivers (ApcCache, MemcachCache etc). This then does not become an issue. It's also worth pointing out that D2 supports 3 types of caching, metadata, query (DQL conversion) and result (Database result caching). All are configurable with different cache drivers.

这篇关于主义2基本代理,存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆