symfony2 form choice and mongodb

耗尽温柔 提交于 2019-12-10 02:37:39

问题


When using Entity we can load choices from Entity via form field type entity

$builder->add('group', 'entity', array(
    'class' => 'Fist\CoreBundle\Document\Group',
));  

but when using mongodb document what is the best way to inject select options from Document?

in my case load all Groups from Group document. Is there better way to do that than passing to form constructor?

Thank you all


回答1:


The Doctrine MongoDB ODM equivalent of EntityType is Symfony\Bundle\DoctrineMongoDBBundle\Form\Type\DocumentType. DocumentChoiceList, DocumentsToArrayTransformer, and DocumentToIdTransformer are also included in DoctrineMongoDBBundle and parallel their ORM equivalents.




回答2:


Change entity to document, and you can just use the shortcut. ex: FistCoreBundle:Group




回答3:


I had to partially stray from Dylan Oliver's answer.

Symfony\Bundle\DoctrineMongoDBBundle\Form\Type\DocumentType

could not be found, as of November 2016 DocumentType seems to reside here:

Doctrine\Bundle\MongoDBBundle\Form\Type\DocumentType


来源:https://stackoverflow.com/questions/7709323/symfony2-form-choice-and-mongodb

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