简体   繁体   English

symfony 中的实体和存储库到底是什么?

[英]What exactly are entities and Repositories in symfony?

I am developing a new website and REST API in symfony(v4.3),in which I have no experience.我正在symfony(v4.3)中开发一个新网站和REST API,我没有经验。 There is something that concerns me about the MVC.关于 MVC,我有些担心。 As you know you put your Controllers in the Controllers folder but what about the Entities and Repositories.如您所知,您将控制器放在 Controllers 文件夹中,但实体和存储库呢? I can't define which one of them is the model and where do I build my queries, however I started doing it in the entities.我无法定义其中哪一个是 model 以及我在哪里构建查询,但是我开始在实体中进行。

I have read the documentation and some other forums and articles but there is nothing that can tell me where I should do it.我已经阅读了文档和其他一些论坛和文章,但没有什么可以告诉我应该在哪里做。

Entities are the memory objects of one record out of a database-table.实体是数据库表中一条记录的 memory 对象。 For example you could have a User entity that has a property $id, $username, $email and $password.例如,您可以有一个具有属性 $id、$username、$email 和 $password 的用户实体。 It holds the data from one user.它保存来自一位用户的数据。 The User entity will store its data into the database-table "user" which has the columns "id", "username", "email" and "password". User 实体会将其数据存储到数据库表“user”中,该表具有“id”、“username”、“email”和“password”列。

The UserRepository will hold all database queries that you can use to retrieve data out of the "user" database-table (and related tables). UserRepository 将保存所有数据库查询,您可以使用这些查询从“用户”数据库表(和相关表)中检索数据。 From your controller you can call a method from the repository class that will run a query and return a result.从 controller 中,您可以调用存储库 class 中的方法,该方法将运行查询并返回结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是Symfony中的存储库,容器和服务 - What are repositories, containers and services in Symfony 如何将定制的学说存储库绑定到symfony中的映射实体? - How can I tie bespoke doctrine repositories to mapped entities in symfony? 从Symfony2中的实体和存储库登录的正确方法 - Correct way to log from Entities and Repositories in Symfony2 Symfony2捆绑包应确切包含什么? - What exactly should a Symfony2 bundle contain? 在 symfony 中使用捆绑实体的标准方法是什么? - What is the standard way to use a bundle's entities in symfony? 使用以映射的超类配置中的实体使用存储库的以教义为中心的方法是什么? - What is a Doctrine-centric approach to work with repositories that use entities in mapped superclass configuration? Symfony单元测试模拟2存储库 - Symfony Unit Test mock 2 repositories 将存储库注入Factory Symfony2 - Injecting repositories into Factory Symfony2 PHP中的实体“对象”,“对象引用”,“对象标识符”,“对象访问器”到底是什么? 它们如何运作? - What exactly are the entities 'Object', 'Object Reference', 'Object Identifier', 'Object Accessors' in PHP? How they function? Symfony:使用表单编辑实体 - Symfony: Editing entities with form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM