colinfrei / bitfield-type-bundle
为 Symfony Forms 添加位字段类型
2.7.0
2018-07-17 06:13 UTC
Requires
- symfony/symfony: ~3.4
This package is not auto-updated.
Last update: 2024-09-28 13:58:06 UTC
README
安装
将以下内容添加到您的依赖文件中
[ColinFreiBitFieldFormTypeBundle]
git=http://github.com/colinfrei/Symfony-Bitfield-Form-Type-Bundle.git
target=bundles/ColinFrei/BitFieldTypeBundle
在 app/autoload.php 文件中注册 ColinFrei 命名空间,通过在 $loader->registerNamespaces(array(
数组中添加此行
'ColinFrei' => __DIR__.'/../vendor/bundles',
在 app/AppKernel.php 文件中注册包,通过在 registerBundles() 函数中的 bundles 数组中添加此行
new ColinFrei\BitFieldTypeBundle\ColinFreiBitFieldTypeBundle(),
用法
当向表单添加字段时使用 BitfieldType
类,并传递一个选项数组,如以下示例所示,该示例来自 Symfony 文档
use ColinFrei\BitFieldTypeBundle\Form\Type\BitfieldType;
$form = $this->createFormBuilder($task)
->add('task', 'text')
->add('dueDate', 'date')
->add('type', BitfieldType::class, array(
'choices' => array('Annoying' => '1', 'Fun' => '2', 'Cool' => '4', 'Takes a while' => '8'),
'choices_as_values' => true
)
->getForm();