[英]What is the difference between repositories and table objects in cakephp v3.x?
I have been using Cakephp ver2.x and just started migrating to Cakephp v3.x. 我一直在使用Cakephp ver2.x,并且刚开始迁移到Cakephpv3.x。 When I tried using the new ORM, I am baffled by basic concepts like repositories and table objects.
当我尝试使用新的ORM时,我对诸如存储库和表对象之类的基本概念感到困惑。 What is the difference between repositories and table objects?
存储库和表对象有什么区别?
A repository can be anything while a table, as the name states, is just a table. 顾名思义,表可以只是表,而存储库可以是任何东西。
http://api.cakephp.org/3.0/class-Cake.ORM.Table.html http://api.cakephp.org/3.0/class-Cake.ORM.Table.html
Represents a single database table.
代表一个数据库表。
Exposes methods for retrieving data out of it, and manages the associations this table has to other tables.
公开从中检索数据的方法,并管理该表与其他表的关联。 Multiple instances of this class can be created for the same database table with different aliases, this allows you to address your database structure in a richer and more expressive way.
可以为具有不同别名的同一个数据库表创建此类的多个实例,这使您能够以更丰富和更具表达力的方式处理数据库结构。
http://api.cakephp.org/3.0/class-Cake.Datasource.RepositoryInterface.html http://api.cakephp.org/3.0/class-Cake.Datasource.RepositoryInterface.html
Describes the methods that any class representing a data storage should comply with.
描述表示数据存储的任何类应遵循的方法。
A data storage can be any kind of storage system, even one that doesn't know tables like a graph DB or document based system. 数据存储可以是任何类型的存储系统,甚至是不知道表(例如图形数据库或基于文档的系统)的存储系统。
It is always simple to just check the API documentation and code for this kind of questions. 仅需检查API文档和代码中的此类问题,总是很简单。 The code is pretty well documented.
该代码已被很好地记录。 Also the way this works becomes obvious then:
然后,这种工作方式也变得显而易见:
class Table implements RepositoryInterface, EventListenerInterface
Table implements the interface defined by RepositoryInterface. 表实现了RepositoryInterface定义的接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.