Answer the question
In order to leave comments, you need to log in
How to display some of the data correctly?
Guys, in the "Firm" class, there is a method for displaying all firms in an array. public function selectAll(){}
Inside, a database query is created and an array is returned. Sometimes you need to display the entire array of firms (about 100, and sometimes divided into pages LIMIT 30, 30).
Did I understand correctly that all this goodness is done in one method and the request itself is modified through the parameter passed to selectAll (). That is, selectAll() will display the entire array. selectAll(30,30) will output with a constraint.
PS. Do not cling to (30.30). There will be an associative array, just for clarity.
Answer the question
In order to leave comments, you need to log in
If you understand correctly, it is better to do two methods. One for the entire list, the second for pagination. But inside them, part of the code will be the same, it can be moved to a separate method (if it is large).
Dance
from DI
You need to decide what methods are needed from the class.
If the selection is of all firms, then something like getAll
If the selection is by id, then getById(id)
, etc.
It is necessary to proceed from the interface that the client of the class requires. And the class itself implements it.
This way you hide things that are not required by the client and give yourself the opportunity to change the implementation of the class without changing its client.
Try to do the implementation of the class without repetition using hidden methods.
If there are places in the class that will change frequently, then take them out to other classes and delegate execution to them. SRP
Well, read about the rest of the SOLID principles. To use them. Without fanaticism. This will greatly help you make code that is understandable to yourself and others. Well, tested.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question