sasedev/hidden-entity-type-bundle

用于Symfony实体的隐藏字段。(最初fork自https://github.com/shapecode/hidden-entity-type-bundle)

安装: 240

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.2 2020-08-25 09:02 UTC

This package is auto-updated.

Last update: 2024-09-25 17:56:18 UTC


README

用于Symfony表单的隐藏实体类型。

这是什么?

这是一个允许你在表单中添加一个将被显示为隐藏输入的实体的Symfony表单类型。

安装

步骤 1:使用composer下载HiddenEntityTypeBundle

$ composer require sasedev/hidden-entity-type-bundle

Composer会将此包安装到您的项目vendor目录中。

步骤 2:启用包

如果flex没有为您完成,请在此配置中启用包

<?php
// config/bundles.php

return [
    // ...
    Sasedev\HiddenEntityTypeBundle\SasedevHiddenEntityTypeBundle::class => ['all' => true],
    // ...
];

用法

简单用法

您可以在表单中使用此类型,就像这样

<?php

use Sasedev\HiddenEntityTypeBundle\Form\Type\HiddenEntityType;

// ...
$builder->add('entity', HiddenEntityType::class, array(
    'class' => YourBundleEntity::class
));

您也可以使用HiddenDocumentType::class类型

<?php

use Sasedev\HiddenEntityTypeBundle\Form\Type\HiddenDocumentType;

// ...
$builder->add('document', HiddenDocumentType::class, array(
    'class' => YourBundleDocument::class
));

只有一个必需的选项 "class"。您必须指定要用于表单的实体类,格式为Symfony。

高级用法

您可以使用以下方式在表单中使用HiddenEntityTypeHiddenDocumentType类型

<?php
// ...
$builder->add('entity', HiddenEntityType::class, array(
    'class' => YourBundleEntity::class, // required
    'property' => 'entity_id', // Mapped property name (default is 'id'), not required
    'multiple' => false, // support for an array of entities, not required
    'data' => $entity, // Field value by default, not required
    'invalid_message' => 'The entity does not exist.', // Message that would be shown if no entity found, not required
));

报告问题或功能请求

请随意报告任何问题。如果您有改进的想法,请修改并提交拉取请求。

原文

原始源代码来自Glifery(https://github.com/Glifery/EntityHiddenTypeBundle),但似乎不再受支持。我因Shapecode的包不支持php 7.2而将其代码fork到我的仓库(https://github.com/shapecode/hidden-entity-type-bundle),因为我不能将所有服务器升级到php 7.4