M
M
Maxim2018-06-17 12:05:42
Yii
Maxim, 2018-06-17 12:05:42

YIi Advanced use of models. How to use?

Hello. There is a simple question. It concerns the input and modification of data by the user. Rather even more input. As well as the models themselves and their use.
I saw that some use their models to add data, instead of AR models. For example, there is such a use in the standard execution of the application - this is the registration implementation.
It uses its own signup model and upon successful validation, the model creates an AR model and adds data to the database.
Questions:
1. Why is a separate form model made?
2. Who else uses models to offload the main model and how? Where to read about it?
3. What is the best way to enter data into a table? Through an AR model or a separate form model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-06-17
@myks92

1) Because this should be done according to the pattern, it’s just that the Yii developers inherited ActiveRecord from the Model for general convenience and speed up rapid development
2) The model in Yii can be interpreted as a DTO design pattern with the possibility of validation
3) It’s up to you. (But "correct" through the model)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question