From Doctrine Query to QueryBuilder in a Simfony2 entity field type

独自空忆成欢 提交于 2019-12-03 09:22:20

From Symfony2 docs:

query_builder - type: Doctrine\ORM\QueryBuilder or a Closure <---

If specified, this is used to query the subset of options (and their order) that should be used for the field. The value of this option can either be a QueryBuilder object or a Closure. If using a Closure, it should take a single argument, which is the EntityRepository of the entity.

Now, I haven't got time to try an example but it seems to me that if you use Closure you could return ArrayCollection (or at least array) of target entity objects. Your Closure gets object of EntityRepository as an argument so there's no need to rewrite all that stuff.

Mind giving it a shot? :)

UPDATE

... sorry for kept you waiting...

It seems that it's not possible this way. Instead you would have to use choice form type and feed entity objects (or objects repository as I did) manually.

I've made some simplified example here: http://ideone.com/LHdi2E

Hope this helps...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!