I am try to do the same thing, I know that's not a good idea inject some 
service into the Enty, but what would be the best practice for something 
like:

having a collection of entity (nested set category) in a page which need to 
print the "path", in the repository we get anything to construct the path 
but it's not accessible in the twig view.

My solutions :

1) Inject entity repository to the entity (during load event), in that case 
I could have a method that can call repository methods (Bad: break data 
mapper concept)
2) create a twig extension that has entity manager / entity repository 
service injected, to be able to call some repository methods from a twig 
view (Bad: the view has nothing to do with business logic)
3) do the job in the controller: explode object collection to array and 
inject properties needed (Bad: why should object be explode to array)
4) add some unpersisted properties to the entity, fill them in the 
controller or with the load event. (Bad: I think it also against data mapper 
concept)
5) stop using repository methods (cascade get parents to build the path) (Bad: 
to much extra queries and a lots of case that can't be done )


I don't see what is the best solutions, but maybe some of the symfony 
masters has the right solution, for this issue which is a simple, but could 
be resume as "how to use a service associated to an entity in the view"



-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to