开发者

Using doctrine translatable together with Symfony 2 forms

开发者 https://www.devze.com 2023-04-10 03:21 出处:网络
I have Entity in my app, which has 2 translatable fields, using Doctrine Translatable Extension: class Page implements Translatable

I have Entity in my app, which has 2 translatable fields, using Doctrine Translatable Extension:

class Page implements Translatable
{
    /......

    /**
     * @var string $name
     * @Gedmo\Translatable
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @var text $content
     * @Gedmo\Translatable  
     * @ORM\Column(name="content", 开发者_Python百科type="text")
     */
    private $content; 

 /........
}

I use one table for multiple entities translations. Now i would like to use one form to get the original and translated (to 1 language) values for these attributes, so it should have 4 fields.

I've defined new form derivating from AbstractType and tried to add those 2 fields using FormBuilder, but it says that their corresponding entities do not contain these fields. I've tried to add these fields to entities, and declare getters for them, but the only way i know to get translations for entities is to use dedicated entity manager and AFAIK providing entity manager access to entity isn't good practice.

Is there a way to use forms to handle such thing?


I know it's an old question, but anyway.

You could put the fields for translated content using FormBuilder with attribute:

array('mapped'=>false)

Take the data like this:

$form->get('field_name')->getData();

and then persist it like this

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#multi-translations

I hope it helps somebody.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号