Reputation: 11
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
here is my error
No attached service to type named `doctrine_phpcr_string`
Upvotes: 0
Views: 719
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