简体   繁体   中英

php,symfony 2 filter case sensitive

I want to ignore case in a filter , My code:

if (strtolower(isset($filterObject['name'])) && null !== strtolower(($filterObject['name']))) {
    $queryFilter->addStringFilter("name", ($filterObject['name']));
}

If you want to ignore the casesensitivity of the addStringFilter by lowercasing the object you would just have to use strtolower($filterObject['name']). strtolower lowercases the string given.

On that note you are using strtolower on an isset function result which won't do a thing there (as isset returns no string).

So you should change your sourcecode to:

if (isset($filterObject['name']) && null !==  strtolower(($filterObject['name']))) 
{
    $queryFilter->addStringFilter("name", strtolower(($filterObject['name'])));
}

Btw one case you didn't check is if $filterObject['name'] is empty (not sure if it is possible as I don't know your remaining code. If it CAN be possible you want to add another and into the if:

&& $filterObject['name']

That would make sure that it is filled with more than an empty string. Thus the if part would change to:

 if (isset($filterObject['name']) && $filterObject['name'] && null !==  strtolower(($filterObject['name']))) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM