3

基本的なフィールドセット テンプレートを作成しようとしています。私が持っているのはこれです:

fieldset.html.twig

{% form_theme form _self %}
{% block form_row %}
    <fieldset>
        <legend></legend>
        {{ form_row(form) }}
    </fieldset>
{% endblock %}

FieldsetType.php

class FieldsetType extends AbstractType
{
    public function __construct($tituloFieldset="")
    {
        $this->titulo = $tituloFieldset;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'attr' => array(
                'title'=>$this->titulo
            ),
           'mapped'=>false
        ));
    }

    public function getParent()
    {
        return 'form';
    }

    public function getName()
    {
        return 'fieldset';
    }

    private $titulo;
}

現在の使用状況

$builder->add('nestedform', new FieldsetType('legend'));

私はすべてを試しました:タイトルをラベルとして追加する(フィールドレンダリングのない追加のラベル)、フォーム全体をテンプレート化する(この場合、追加のフィールドセットを追加できません)など。

私は何をすべきか?

4

2 に答える 2

4

あなたは正しい軌道に乗っています。ここで簡単な例を見つけることができます: https://gist.github.com/spcmky/8512371

于 2014-01-19T23:46:47.480 に答える