scaytrase/symfony-stored-forms-bundle

此包已被弃用且不再维护。未建议任何替代包。

可配置的Web表单

3.0.0 2015-07-21 21:52 UTC

README

Build Status

Symfony2 Stored Forms Bundle

描述

此扩展包深受Drupal 6 CCK模块机制的启发。它允许动态创建自定义Web表单,具有高度可定制的输入,无需更改源代码。只有在需要扩展可用的字段类型集时,才需要更改。

这是在 Doctrine2 存储的 Symfony2 表单组件的基础上重造轮子的尝试。

安装

安装此扩展包的最佳方式是使用composer

    composer require "scaytrase/symfony-stored-forms-bundle:~3.0"

并将扩展包包含在应用程序扩展包列表中

    class AppKernel extends Kernel
    {
        public function registerBundles()
        {
            $bundles = array(
                new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
                \\ ....
                new ScayTrase\StoredFormsBundle\StoredFormsBundle(),
    

使用方法

最简单的方法在测试套件中展示

        $string = new StringField();
        $string->setName('string_type');

        $text = new TextAreaField();
        $text->setName('text_type');

        $number = new NumberField();
        $number->setName('number_type');

        $choice = new ChoiceField();
        $choice->setName('choice_type');
        $choice->setChoices(array('choice1', 'choice2'));

        /** @var AbstractField[] $fields */
        $fields = array($string, $text, $number, $choice);

        $builder = $this->factory->createBuilder('form');

        foreach ($fields as $field) {
            $field->buildForm($builder);
        }

然后,只需用手动 FormInterface::submit($data) 调用或通过 FormInterface::handleRequest($request) 来填充表单。表单中的每个字段都将返回一个 AbstractValue 对象(更多信息请参阅字段类)。字段和值都已准备好存储到数据库中。