[英]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.