php - How to handle a 1:n relation in smyfony2 forms? -
i need project translated entities , easy way maintain content. 1 "myentity" can have many "myentity_trans".
this easy far, need dynamic form in easy way without changing in symfony2 default behaviour.
when create/edit "myentity", need "myentity_trans" subform every language. there common way handle this?
my entities example:
myentity - id - status myentity_trans - id - myentity_id - language_id - ... language - id - name
edit 1: here form configuration works on edit, if got related entities:
$builder ->add('name') ->add('trans', 'collection', array( 'type' => new retailertranstype(), 'allow_add' => true, 'allow_delete' => true ));
now empty forms every possible language, user can easy create translations. tried use query builder, don't work collection type.
you should either use gemo\doctrineextensions\translatable, can integrated symfony2 using stof\doctrineextensionsbundle
... or tip if using php 5.4+ traits available knplabs\doctrinebehaviors\translatable.
in order integrate these nicely forms use a2lix\translationformbundle. bundle provides you're looking - collection of translations languages.
see my answer here quick insight on using doctrinebehaviors\translatable , current locale proxy found comfortable solution.
just create class entity
, entitytranslation
, include proxy lines ... call $entity->getproperty()
-> current locale applied automatically. easy can :-)
Comments
Post a Comment