PHP Doctrine2 搜索 "Like" 数组“%$array%”

PHP Doctrine2 search "Like" with an Array "%$array%"

Doctrine2.5 与 PHP5.6

我有很多东西要搜索,例如: 在 table 个用户中,我想搜索所有拥有 字段名称中的名称 "Reis" 或 "Shimidt"。使用数组

$arraySearch = ['Reis', 'Shimidt'];

我想带来例如以下条目,

我试过这样的事情:

$this->query->andWhere(" pb.name LIKE '%:name%' ");
$this->query->setParameter('name', $name, \Doctrine\DBAL\Types\Type::SIMPLE_ARRAY);

不行,我也这样试过,但显然返回数组到字符串的转换:

$this->query->setParameter('name', '%'.$name.'%', \Doctrine\DBAL\Types\Type::SIMPLE_ARRAY);

有什么想法可以解决这个问题而不用编写混乱的代码吗?

我建议你使用这样的东西:

foreach ($arraySearch as $search) {
    $this->query->orWhere(" pb.name LIKE :search ");
    $this->query->setParameter("search", '%'.$search.'%');
}

试试这个:

$this->query->setParameter('name', implode("%', OR name LIKE '%", $arraySearch));