scaytrase / symfony-storable-forms
此包已被废弃,不再维护。未建议替代包。
Web可配置表单
3.0.0
2015-07-21 21:52 UTC
Requires
- php: >=5.4
- doctrine/orm: ~2.3
- scaytrase/symfony-autoregistry: ~2.0
- symfony/form: ~2.4
- symfony/validator: ~2.3
Requires (Dev)
- phpunit/phpunit: ~4.6@stable
- scaytrase/symfony-test-utils: ~1.0
Suggests
- scaytrase/symfony-form-extensions: For key-value collection functional
This package is not auto-updated.
Last update: 2022-02-01 12:40:53 UTC
README
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
对象(更多信息请参阅字段类)。字段和值都已准备好存储到数据库中。