Sonata administrator, user request in filter

I am using SonataAdminBundle and I have a question about filters in the MyEntityAdmin class.

I have the first function protected function configureFormFields(FormMapper $formMapper)to list all the fields that will be displayed when creating / editing forms.

If I have a field type entity, I can do something like this:

->add('commercial', 'entity', array(
                'class' => 'MyBundle:User',
                'query_builder' => function(EntityRepository $er) {
                  return $er->createQueryBuilder('u')
                            ->groupBy('u.id')
                            ->orderBy('u.id', 'ASC')
                            ->setParameters(array(1 => 'Commercial'));
              },)
            )

But I have another protected function configureDatagridFilters(DatagridMapper $datagridMapper)for the protected function configureDatagridFilters(DatagridMapper $datagridMapper)fields in the filter forms, and I have to do the same, a user request for the field type of the object, but if I do the same, I have an error:

No attached service to type named 'entity'  

How can i do this?

+5
source share
1 answer

The configuration of the filters differs from the configuration of the form in the sonata hadron package.

: http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/filter_field_definition.html

configuratDataFilters, : , , , .

, query_buider , :

->add('commercial', null, array(), 'entity', array(
          'class' => 'MyBundle:User',
          'query_builder' => function(EntityRepository $er) {
               return $er->createQueryBuilder('u')
                         ->groupBy('u.id')
                         ->orderBy('u.id', 'ASC')
                         ->setParameters(array(1 => 'Commercial'));
           }
))
+15

All Articles