没有为类Doctrine \ ORM \ PersistentCollection定义实体管理器

时间:2018-07-19 13:10:28

标签: doctrine-orm sonata-admin symfony4

我将Symfony 4.1SonataAdminBundle 3.36一起使用。

ModelType::class关系字段调用标签上设置ManyToMany时,出现此错误:

  

没有为Doctrine \ ORM \ PersistentCollection类定义实体管理器

我也无法使用sonata_type_modelsonata_type_model_list

src/Admin/CategoryAdmin.php

namespace App\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Form\Type\ModelListType;


class FactureAdmin extends AbstractAdmin
{
    protected $datagridValues = [

        // display the first page (default = 1)
        '_page' => 1,

        // reverse order (default = 'ASC')
        '_sort_order' => 'DESC',

        // name of the ordered field (default = the model's id field, if any)
        '_sort_by' => 'dateIn',
    ];

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->tab('Facture')
                ->with('Infos Générales', ['class' => 'col-md-8'])
                    ->add('title', TextType::class, array('label' => 'Libellé'))
                    ->add('slug', TextType::class, array('label' => 'Slug', 'required' => false))
                    // ->add('status')
                    ->add('notice', TextareaType::class, array('label' => 'Remarques', 'required' => false))
                ->end()
                ->with('Traitement', ['class' => 'col-md-4'])
                    ->add('user', EntityType::class, [
                        'class' => User::class,
                        'choice_label' => 'username',
                        'label' => 'Chargé',
                    ])
                    ->add('tags', ModelType::class, [
                        'attr' => [
                            'expanded' => true
                        ]
                    ])
                    // ->add('tags', 'sonata_type_model', array('expanded' => true, 'multiple' => true))
                    ->add('duration', null, array('label' => 'Durée (Nombre de jours)', 'required' => false))
                    ->add('status',  CheckboxType::class, array('required' => false, 'label' => 'Statut (Payée/Non payée)'), array('transform' => true))
                    ->add('active')
                ->end()
            ->end()
            ->tab('Prestataire')
                ->with('Identité', ['class' => 'col-md-6'])
                    // ->add('status')
                    ->add('prestataire', EntityType::class, [
                        'class' => Prestataire::class,
                        'choice_label' => 'name',
                        // 'label' => 'Sélectionnez le prestataire',
                    ])
                    ->add('providerName', TextType::class, array('label' => 'Nom représentant'))
                    ->add('providerPhone', TextType::class, array('label' => 'Numéro représentant', 'required' => false))
                    ->add('providerEmail', EmailType::class, array('label' => 'Email représentant', 'required' => false))
                ->end()
            ->end()
            ->tab('Media')
                ->with('Numérisation', ['class' => 'col-md-8 col-md-offset-0', 'description' => 'Veuillez uploader la facture numérisée'])
                    // ->add('status')
                    ->add('billScan', ModelListType::class)
                ->end()
            ->end()
        ;
    }
}

}

1 个答案:

答案 0 :(得分:0)

对我来说,在将'multiple' => true添加到ModelType::class之后,它起作用了:

->add('tags', ModelType::class, [
    'multiple' => true,
    // your other options
])

此后,表单将正确显示。