A
A
Alexey Nikolaev2018-02-01 19:25:38
Programming
Alexey Nikolaev, 2018-02-01 19:25:38

How to call the class that has access to the database?

Good evening.
In MVC, this is often done by the model. But what about in the general case? Now I use the Repository for this, and the fact that the database is the repository remains an implementation detail (something tells me that this solution is far-fetched and semantically incorrect). At the same time, Yii has ActiveRecord, which is bound to a table and is called a model by many.
So what is usually a class whose authority is to access the database to get / save certain entities, for example, User? And what is the right thing to do, to bind such classes to an entity or to a table?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-02-01
@Heian

Yii have an ActiveRecord that is bound to a table

But he does this through several abstractions... In Yii2 itself, https://github.com/yiisoft/yii2/blob/master/framew...
is responsible for working with the database
You seem to be working correctly through the repository.
Here is a good and popular pattern that solves your case:
design-pattern.ru/patterns/data-mapper.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question