我正在为我的应用程序使用SonataAdmin和Symfony2。我有EntryAdmin,这是来自不同机构的协调人的条目列表。当代理用户登录时,我将它们仅限于与其签约的协调人的条目,我通过自定义列表查询来完成。
如下:
$facilitator_array = array();
foreach($facilitators as $facilitator)
{
array_push($facilitator_array,$facilitator->getId());
}
$query->andWhere($query->getRootAlias().'.facilitator IN (:facilitators)');
$query->setParameter('facilitators', implode(", ",$facilitator_array));
生成的查询不会给我结果,因为数组被引用为字符串,如下所示。
SELECT e0_.id AS id0, e0_.name AS name1, e0_.tel AS tel2, e0_.email AS email3, e0_.knows_olx AS knows_olx4, e0_.device_type AS device_type5, e0_.defrauded AS defrauded6, e0_.is_verified AS is_verified7, e0_.is_new AS is_new8, e0_.created_at AS created_at9, e0_.updated_at AS updated_at10, e0_.created_by AS created_by11, e0_.updated_by AS updated_by12, e0_.facilitator_id AS facilitator_id13, e0_.channel_id AS channel_id14 FROM entries e0_ WHERE e0_.facilitator_id IN ('51,61,81,91,101,371') ORDER BY e0_.id ASC
如何删除引号('51,51,81,91,101,371'),因为我已尽我所能但无济于事
答案 0 :(得分:0)
$ids = array_map(function($element){return $element->getId();}, $facilitators);
$query->andWhere($query->getRootAlias().'.facilitator.id IN (:facilitators)');
$query->setParameter('facilitators', $ids);