【问题标题】:SonataAdmin - Custom form template for each formSonataAdmin - 每个表单的自定义表单模板
【发布时间】:2015-03-11 13:58:10
【问题描述】:

我在使用 Sonata Admin Bundle 时遇到问题。我想做的是:

在我的表单中的一些标签之前添加一些文本。比如:

图片的分辨率必须是 ..x.. .

例如我有一个这样的表格:

protected function configureFormFields(FormMapper $formMapper)
{
     $formMapper
         ->add('locale', 'choice', array(
             'choices'   => array('nl' => 'NL', 'en' => 'EN'),
             'required'  => true,
         ))
         ->add('pageid.tag', 'text', array('label' => 'Tag'))
         ->add('description', 'text', array('label' => 'Beschrijving'))
         ->add('content', 'textarea', array('label' => 'Tekst', 'attr' => array('class' => 'ckeditor')))
         ->add('files', 'file', array('required' => false, 'multiple' => true))
    ;
}

现在我想在我的文件输入字段之前添加一些文本。

我现在做的是:

  • 将此添加到我的 config.yml(重载模板/表单配置选项):

    sonata_doctrine_orm_admin:
        # default value is null, so doctrine uses the value defined in the configuration
        entity_manager: ~
    
        templates:
            form:
                - MurisBundle:PageAdmin:form_admin_fields.html.twig
    

但是每个表单都会用到这个,我不能为特定的表单设置特定的表单模板吗?

【问题讨论】:

    标签: php forms symfony sonata-admin sonata


    【解决方案1】:

    您可以在您的管理类中指定表单模板覆盖 getFormTheme 方法。 将此代码添加到您的管理类。

    public function getFormTheme()
    {
         return array_merge(
             parent::getFormTheme(),
             array('MurisBundle:PageAdmin:form_admin_fields.html.twig')
         );
    } 
    

    【讨论】:

      【解决方案2】:

      getPictureUrlFull().'" alt="'.$campaign->getPicture().'" style="margin-top:10px;" />使用“帮助”

      protected function configureFormFields(FormMapper $formMapper)
      {
           $formMapper
               ->add('locale', 'choice', array(
                   'choices'   => array('nl' => 'NL', 'en' => 'EN'),
                   'required'  => true,
                   'help'      => '<img src="'.$entity->getPictureUrlFull().'" alt="'.$entity->getPicture().'" />'               
               ))
      
      )
      

      【讨论】:

      • 我认为帮助文本实际上是在字段之后呈现的,而不是之前
      猜你喜欢
      • 2017-05-02
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2021-12-18
      • 2014-07-12
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      相关资源
      最近更新 更多