gibilogic/hidden-entity-bundle

GiBiLogic 隐藏实体包

1.0.0 2015-10-15 08:59 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:08:52 UTC


README

这是一个包含用于 Symfony 2 的现成隐藏实体表单类型的迷你包。

这基本上是一个隐藏的表单类型,用于存储实体 ID;通过使用 Doctrine ORM 的 ObjectManager,转换器将管理 ID 到实体以及实体到 ID 的转换。

安装

使用控制台命令将此包添加到您的应用的 composer.json 文件中

composer require gibilogic/hidden-entity-bundle

或者,如果您使用 composer.phar,则使用控制台命令

php composer.phar require gibilogic/hidden-entity-bundle

使用方法

在您的表单中,只需向构建器添加一个新的 hidden_entity 字段

/**
 * {@inheritdoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        // ..
        ->add('category', 'hidden_entity', array(
            'required' => true,
            'class' => 'AppBundle:Category'
        ))
        // ..
    ;
}

class 选项是必须的,必须包含您的实体类名(如上例所示)。