0
在存儲庫中,我需要一個自定義的getALL查詢來檢查基於數據數組的項目。例如我需要能夠發送$ params = ['type'=> ['type1','type2'],'username'=> $ username]但我目前只能發送一個參數,如:$ params = ['鍵入'=>'type1','username'=> $ username]。Doctrine存儲庫接受數組getAll
什麼是增加接受數組(像上面的)這個GETALL查詢?:
public function getAllQuery($params = [])
{
$query = $this->createQueryBuilder('c');
if(count($params))
{
foreach($params as $param => $value)
{
//todo need to make it accept an array of parameters
if(in_array($param, $this->getClassMetadata()->getFieldNames()) && $param != 'deleted')
{
$query
->andWhere(sprintf('c.%1$s LIKE :%1$s', $param))
->setParameter($param, sprintf('%%%s%%', $value));
}
/*code already exists here for checking other parameters
outside of 'type' (e.g. 'username') */
}
}
return $query->getQuery();
}