Answer the question
In order to leave comments, you need to log in
Yii2 RESTful API why use Search model?
Hello again! Generated CRUD via Gii for the post entity, saw the model working with PostSearch in the actions, resaw the method into a simple $model->find()->all(). And actually why do we need these Search and is it necessary to use them?
Answer the question
In order to leave comments, you need to log in
The Search Model is a model that works with data filtering, sorting, and displays it all through a DataProvider.
The model initially does too much, so it's better if you use your own filter form and throw out everything unnecessary from there. The filtering model should not be inherited from the entity and work directly with the base.
The all() method is not recommended for big data. The script may hang.
In the model, it is also convenient to make lists for the drop-down lists of the form.
In short, a SearchModel is a form that you pass data to and filter by. But since it is not only a form, it is called a model. In general, it can be called Filter.
You can and should do without it if you know how. This is all done for fast RAD development.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question