残念ながら、Form Componentは、この機能を提供していません。 しかし、あなた自身で実装したり、サードパーティのバンドルを使用することができます。
FormBuilderInterface
はform generationのための素敵な宣言型のAPIです。 独自の構成形式を定義し、それを使用してフォームを構築することができます。例えば
:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use DOMDocument;
class XmlBasedFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Better if the format will be as similar to the FormBuilder options:
$formConfig = DOMDocument::loadXML(<<<'XML'
<form>
<field name="foo" type="text" label="Foo"/>
<field name="bar" type="textarea" label="Bar"/>
<field name="baz" type="checkbox" label="Baz"/>
</form>
XML
);
foreach ($formConfig->getElementsByTagName('field') as $fieldElement) {
$name = $fieldElement->getAttribute('name');
$type = $fieldElement->getAttribute('type');
$label = $fieldElement->getAttribute('label');
// Build a form element:
$builder->add($name, $type, ['label' => $label]);
}
}
}
また、Config Component、この場合に有用であり得ます。
しかし、すべてのフォーム機能を完全に実装するには、多くの作業が必要です。Dynamic Form Bundleのようなサードパーティのソリューションを使用している場合。そのバンドルは、YAML設定ファイルによってSymfonyフォームを生成します。 (私は、このソリューションでいくつかの経験を持っているし、それがうまく動作します。)あなたがsymfonyで必要なすべてを構築することができますが、溶液中に組み込まれて存在しない
。 PS:StackOverflowのガイドライン、[StackOverflowでどのような話題を聞くことができますか?](http://stackoverflow.com/help/on-topic)、[どうすれば良い質問ができますか?](http: /stackoverflow.com/help/how-to-ask)。 –