What is the significance of one model per table in the PHP framework

in many frameworks, each table corresponds to a model,. We usually add a service layer in the MVC to deal with business logic. Why not directly manipulate the db class in the service layer

What is the advantage of the

framework doing this (one model per table)
Thank you

Sep.01,2021

now let's talk about three popular frameworks, foreign Laravel and Symfony and or internal ThinkPHP 5. There is no so-called Service layer in these three. Service is written by developers themselves. The main meaning of Model in these three frameworks is to define the data relationship, in other words, to define the relationship between the table and the table. For example, in Laravel, a user is a User model, corresponding to the users table, and a Post model corresponding to the posts table. In the posts table, there is a users.id field corresponding to the user_id field. So you can use the first method in the User model:

  

is just plain and simple. Try not to directly manipulate the table, but the encapsulation method, so that it is more controllable

Menu