greg0ire / enum-bundle
v3.0.0
2016-04-25 19:33 UTC
Requires
- greg0ire/enum: ^2.0
- symfony/form: ~2.3|^3.0
- symfony/http-kernel: ~2.3|^3.0
Requires (Dev)
- phpunit/phpunit: ~4.1
- symfony/phpunit-bridge: ~2.7|^3.0
README
此包已被废弃,推荐使用greg0ire/enum
EnumBundle
在Symfony2项目中集成greg0ire/enum。这实际上还不是真正的bundle,但它依赖于symfony/form,如果需要配置,它有朝一日可能会成为一个真正的bundle。
- 它依赖于symfony/form
- 如果需要配置,它可能有一天会成为一个真正的bundle
安装
composer require greg0ire/enum-bundle
用法
该bundle提供自己的BaseEnum
类。它继承自greg0ire/enum的BaseEnum
类,并提供了额外的方法getChoices()
,该方法用于作为选择小部件的choices
选项的值。它有一个强制参数,是一个sprintf
格式化字符串,允许您选择如何生成标签。
<?php use Greg0ire\EnumBundle\BaseEnum; final class ColorType extends BaseEnum { const BLACK_WHITE = 'black-white', COLOR = 'color', COLORIZED = 'colorized' ; }
片刻之后,在另一个文件中...
<?php class MyType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add( 'aspect_ratio', 'choice', array('choices' => ColorType::getChoices('color_type_%s')) ); } }
您需要为
color_type_black-white
color_type_color
color_type_colorized
创建翻译