shapecode/hidden-entity-type-bundle

隐藏字段用于Symfony实体

6.0.0 2023-12-02 14:40 UTC

This package is auto-updated.

Last update: 2024-08-31 00:29:52 UTC


README

Symfony表单的隐藏实体类型。

paypal

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads License

这是什么?

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

安装

步骤1:使用composer下载HiddenEntityTypeBundle

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

Composer会将该捆绑包安装到您的项目的vendor目录中。

步骤2:启用捆绑包

在配置中启用捆绑包,如果flex没有为您完成此操作

<?php
// config/bundles.php

return [
    // ...
    Shapecode\Bundle\HiddenEntityTypeBundle\ShapecodeHiddenEntityTypeBundle::class => ['all' => true],
    // ...
];

使用方法

简单使用

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

<?php

use Shapecode\Bundle\HiddenEntityTypeBundle\Form\Type\HiddenEntityType;

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

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

<?php

use Shapecode\Bundle\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
));

报告问题或功能请求

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

原始

原始源代码来自Glifery (https://github.com/Glifery/EntityHiddenTypeBundle),但似乎不再受支持。