The CakePHP framework is a layered structure. My question is:
Where (theoretically) is the best place to implement data query functions? In models or controllers?
With “data query functions” I mean functions like getItemsWithSomeInfo($idItem) etc., i.e functions that are not actions.
Currently, I am implementing these functions in the controller, but I think there are other frameworks in which these functions (or methods) are implemented in the model layer.
I searched on Stackoverflow and found similar issues (Where/how to store custom functions (or methods) in CakePHP), but (in my opinion) are not good answers.
Its better to place such functions in your Model then in Controllers. All data related codes should be in the model. It is always a better idea in the long run, when it comes to refactoring or testing. You know exactly where to find the code. And it can be re-used without copy & paste in other actions/controllers.