omouren/document-id-form-bundle

该包最新版本(1.4)没有提供许可证信息。

提供 "document_id" 表单类型

1.4 2016-06-23 11:59 UTC

This package is auto-updated.

Last update: 2024-09-16 03:31:23 UTC


README

使用 Doctrine ODM 提供 "document_id" 表单类型。基于 Gregwar : FormBundle 的工作。

安装

composer require omouren/document-id-form-bundle.

在应用程序内核中注册该包

<?php
// app/AppKernel.php
//...
public function registerBundles()
{
    $bundles = array(
        ...
        new Omouren\DocumentIdFormBundle\OmourenDocumentIdFormBundle(),
        ...
    );
...

在配置文件中添加以下内容到 twig 块之后

# app/config/config.yml
# Twig Configuration
twig:
    ...
    form_themes:
        - 'OmourenDocumentIdFormBundle::document_id_type.html.twig'

用法

document_id 是一个包含文档 ID 的字段,这假设您设置了 JavaScript 或任何 UI 逻辑来自动填充它。

用法类似于文档字段类型,除了查询返回唯一结果。一个例子:

<?php
//...
$builder
    ->add('city', 'document_id', [
        'class' => 'Project\Entity\City',
    ])
    ;

这里将使用 ->find($value)

您也可以通过将 hidden 选项传递为 false 来显示字段

<?php
//...
$builder
    ->add('city', 'document_id', array(
        'class' => 'Project\Entity\City',
        'hidden' => false,
        'label' => 'Enter the City id'
    ))
    ;

使用 property 选项,您还可以使用除主键之外的标识符

<?php
//...
$builder
    ->add('recipient', 'document_id', array(
        'class' => 'Project\Entity\User',
        'hidden' => false,
        'property' => 'login',
        'label' => 'Recipient login'
    ))
    ;