Answer the question
In order to leave comments, you need to log in
Where to store custom business logic classes in Yii2 and is it worth storing database queries in its model?
Hello everyone, please help me with this issue. Yii2 advanced, let's say there is a table model, located in the frontend/models/Review.php folder, it describes the table of the same name in the "review" database and is inherited from the ActiveRecord class, the table contains a set of fields and we need to get, say, all records by date. We create a public static function getReviewByData( $data )... method that returns our posts to us. Is it right to make the model thick and store all the logic there, all methods for getting and writing data, and then call them in the controller, or is it worth creating a separate class for CRUD manipulations and calling methods from it, or in general (I saw examples when creating queries to the database in view, which I think is fundamentally wrong). And another question, where in the advanced template to store business logic (its classes), what are the correct practices (of course, to have the possibility of autoloading classes using standard yii2 tools). Let's say I want to implement some pattern, I should store the whole pattern in any one namespace or different classes and interfaces in different namespaces... Thanks in advance for your answer.
Answer the question
In order to leave comments, you need to log in
the table contains a set of fields and we need to get, say, all records by date. We create a public static function getReviewByData( $data )... method that returns our posts to us. Is it right to make the model thick
Usually they make controllers and models thin, and all the noodles are fenced in separate classes-repositories.
See repository pattern
Create a public static function getReviewByData( $data )... method that returns our posts to us
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question