I’ve discovered that when I pass doctrine entities to our PHP templates, the designer can start calling setters and change the data. This is no big deal normally except there are pages that perform sub-requests so these changes are being seen by the controller and have the potential to be saved to the database (the identity map pattern returns the object rather than refreshing from storage)!
Is there any way to prevent the templates from changing the data?
(I’ve tried detaching entities before passing them but that makes the doctrine proxies not return data. I really don’t want to lose the lazy loading)
Consider using the deferred explicit change tracking policy:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/change-tracking-policies.html
Only entities which you explicitly persist will be considered for updating. So incidental updates done in a template will not be saved.
I suppose you could also try the Notify policy and, with a bit of magic, disable the notify senders to make your entities basically read only.