【问题标题】:Q: Silex 2.3 and custom form type should use custom templateQ: Silex 2.3 和自定义表单类型应该使用自定义模板
【发布时间】:2018-12-10 13:25:55
【问题描述】:

我使用 Silex 2.3 和 Symfony 4.2.0 的目标是编写自定义表单类型。这种表单类型应该显示一个图像和一个文本字段(或选择,我还不知道)。我们称之为 TextImageType。

所以,我创建了一个 TextImageType:

<?php
  namespace App\Form\Type;

  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\Extension\Core\Type\TextType;

  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\Form\FormInterface;
  use Symfony\Component\Form\FormView;
  use Symfony\Component\OptionsResolver\OptionsResolver;

  class TextImageType extends AbstractType {
  ....
  public function getBlockPrefix() {

      return 'textimage';
  }
}

加载此类有效;如果我在文件中添加错误的代码,我会得到一个错误。 现在,我尝试添加一个仅包含该调试代码的 textimage-widget.html.twig:

{% block textimage_widget  %}
Hello world
<input type="text">
{% endblock %}

我期待一个“小部件”,告诉我“Hello world”和一个输入字段。但是小部件不是从模板/表单/textimage-widget.html.twig 加载的,所以我需要一个简单的工作示例,如何将自定义表单类型添加到 Silex 系统。

提前致谢!

【问题讨论】:

    标签: php silex


    【解决方案1】:

    好吧,我找到了解决方案: 我在 templates/theme 目录中添加了一个表单主题,其中包含一个 textimage_widget 并在我的模板文件中通过 form_theme 加载主题。

    【讨论】:

      猜你喜欢
      • 2013-03-17
      • 2011-10-05
      • 2015-11-28
      • 2012-07-15
      • 1970-01-01
      • 2018-04-14
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      相关资源
      最近更新 更多