qbbr/entity-hidden-type-bundle

Symfony 2 实体隐藏表单类型

安装次数: 8,466

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

2.0.4 2019-02-15 12:40 UTC

This package is auto-updated.

Last update: 2024-09-14 16:55:40 UTC


README

Latest Stable Version Total Downloads License

安装

步骤 1: 下载 Bundle

Symfony >= 2.8

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

Symfony < 2.8

$ composer require qbbr/entity-hidden-type-bundle 1.*

步骤 2: 启用 Bundle

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Qbbr\EntityHiddenTypeBundle\EntityHiddenTypeBundle(),
        );

        // ...
    }

    // ...
}

用法

<?php
// src/AppBundle/Form/Type/MyType.php
namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
// for Symfony < 2.8 rm use type
use Qbbr\EntityHiddenTypeBundle\Form\Type\EntityHiddenType;

class MyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // for < 2.8 use 'entity_hidden'
            ->add('parent', EntityHiddenType::class, [
                'class' => 'AppBundle\Entity\MyEntity',
            ]);
    }

    // for < 2.8 use getName()
    public function getBlockPrefix()
    {
        return 'my';
    }
}