我无法在symfony3中将标签与字符串连接起来

时间:2017-11-03 11:54:50

标签: string symfony label concatenation symfony-3.1

我无法使用字符串连接标签。

->add('originador', EntityType::class, array(
    'label' =>   "app.label.x_originador".'*',
    'class' => 'AppBundle:Usuario',
    'em' => $options['entityManager'],
    'query_builder' => function (EntityRepository $er) {
        return $er->createQueryBuilder('u');    
    },
    'placeholder' => '',
    'required' => false,
))

'label' => "app.label.x_originador".'*',部分     我需要结果为Originador*,因为标签是必需的值。

我收到的结果是app.label.x_originador*

拜托,帮我搞定 结果Originador*

1 个答案:

答案 0 :(得分:1)

您可以将翻译服务传递给您的表单类型,然后翻译,然后连接如下:

class MyFormType extends AbstractType
{
    private $translator;

    public function __construct(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('originador', EntityType::class, array(
                'label' =>   $this->translator->trans('app.label.x_originador',[], 'domain').'*',
                'class' => 'AppBundle:Usuario',
                'em' => $options['entityManager'],
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('u');
                },
                'placeholder' => '',
                'required' => false,
            ));
        }
    }

juste replace" domain"与您的翻译域。

编辑:但是,最好的解决方案可能是@ ccKep的一个