Answer the question
In order to leave comments, you need to log in
Should the model be separated from data inference and lookup?
There is a client model (class Customer)
Management methods: create(), update(), delete()
Data output methods: getAll(), getSome(array()), getOne(id) (output of all records, some, one. By ID).
There is also a search for getByName, getByRegion and other methods.
Question 1 . basis. Whether to create a CustomerSearch class. You can block anything in it, returning only an ID array, which is then passed to the main Customer class. Or is it better to "infinitely populate" the Customer class?
Question 2. There was a desire to pull the create (), update (), delete () methods into the CustomerEdit or CustomerAdmin class. is it worth doing that?
Answer the question
In order to leave comments, you need to log in
1. Yes, it's like a repository
$searchCriteria = new CustomerSearchCriteria;
$searchCriteria->setByName("москва");
$customers = $customerRepository->findByCriteria($searchCriteria);//->CustomerCollection
Perhaps it makes sense to create controllers that are responsible for searching and outputting data (If this will increase the readability and understandability of the code). As for me, it's better not to make many models if they work with the same entity
IMHO good style would be to use collections for multiple selection. Something like
$customers = new Collection(new Customer());
$customers->createCollectionByFields(array('somefield'=>'somevalue'));
$customersArray = $customers->getArray(); //return array of objects
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question