Kostya Prosto
Kostya Prosto

Reputation: 11

sonataadmin bundle FILTERING FIELDS AND CASE SENSITIVITY Not working . No attached service to type named `doctrine_phpcr_string`

I try to create case insensitive filtering using sonataadmin bundle and symfony 2 but i get an error.

"symfony/symfony": "2.6.*"
"sonata-project/admin-bundle": "^2.3",

here is adminclass

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper
        ->add('name', 'doctrine_phpcr_string', array(
            'compare_case_insensitiv' => false
        ))

    ;
}

here is documentation

https://sonata-project.org/bundles/doctrine-phpcr-admin/master/doc/reference/filter_field_definition.html#filtering-fields-and-case-sensitivity

here is my error

No attached service to type named `doctrine_phpcr_string`

Upvotes: 0

Views: 719

Answers (1)

Kostya Prosto
Kostya Prosto

Reputation: 11

here is solution :)

  protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name', 'doctrine_orm_callback',
                array('callback'   => array($this, 'yourFunction'),
                    'field_type' => 'search'),
                null,
                array('pattern' => '^[A-Za-z0-9]{1,12}$')
            );

    }

    public function yourFunction($queryBuilder, $alias, $field, $value)
    {
        if (!$value['value']) {
            return;
        }

        $queryBuilder
            ->andWhere("LOWER(u.name) LIKE LOWER(:field)")
            ->setParameter('field', "%{$value['value']}%");

        return true;
    }

Upvotes: 1

Related Questions