I am using symfony 2 and I have a question about code splitting. I would like to make sure that I understand correctly what elements should be in the controller, what is in the service and what is in essence.
Suppose I have a list of documents that I need to display. In each document, before displaying, I must also perform some logical operation (for example, add two variables).
As in understanding the entity class, it only cares about finding and working with data on a single object. I should not enter any custom code there. As I understand it, this should be done by the service.
But should I:
- use the service to go to the list of controllers based on some criteria after completing the required logic,
- or use a controller to load a list of documents, and then go through a document for maintenance to execute some logic?
I would prefer the first approach to match the thin controller (thin controllers, large models), but is this approach true? What code should be in essence, what is in the controller and what is in the service?
In particular, where should I relate to the entity manager - in the controller or, rather, in the service?
Let me also pretend that in many places in my application I need to check if the document is complete before allowing the user to perform any action (for example, edit it). It should definitely be either in the service, since another service will be required to verify this. Should I upload the document object object to the controller, send it to the service to check if it can be completed or, rather, upload the document to the service and perform the check?
source share