简体   繁体   中英

Set a translation domain on a form created without a class

I'm trying to create a form with translated labels. I'm not using an AbstractType class, I just want to declare my form in a controller :

$form = $this->createFormBuilder($user)
             ->add('website', 'url', array(
                 'required' => false,
                 'label' => 'profession.website.label'
             ));

How can I add a translation domain to my form ?

I believe you pass it as an array to the 2rd argument for createFormBuilder

$form = $this->createFormBuilder($user, [
    'translation_domain' => 'comment'
])->add('website', 'url', [
    'required' => false,
    'label' => 'profession.website.label'
]);

First argument is the data for the form, the second is the options. http://api.symfony.com/2.0/Symfony/Bundle/FrameworkBundle/Controller/Controller.html#method_createFormBuilder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM