I am using symfony 2
and I have question about code separation. I would like to make sure that I correctly understand what elements should be in a controller, what in a service and what in a entity.
Let's imagine that I have list of documents that I need to display. On each document before displaying I have to also perform some logic operation (e.g. add two variables).
As in understand entity class takes care only on data retrieval and operation on single entity. I should not input there any custom code. As I understand this should be done by a service.
But should I:
I would rather think that the first approach is appropriate to keep controller thin (thin controllers, big models) but is this approach right? What code should be in entity, what in controller and what in a service?
In particular where should I relate to entity manager - in a controller or rather in service?
Let's also pretend that in many place in my app I need to check if document is finalized before allowing user to perform any action (e.g. edit it). This definitely should be either in a service, as another service would be required to check this. Should I however load the document entity object in controller, send it to service to verify whether it may be finalized or rather load document in service and there perform a check?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With