简体   繁体   中英

doctrine search by array

I am using symfony3 and I was wondering whether it is possible to search with doctrine and use a an array as parameters. here is my code:

foreach($statesData as $val){
            $dataState[] = array('id' => $val->getId());
        }
        $cities=$em->getRepository('AppBundle:Cities')->findByStateId($dataState);

I basically want the equivalent to 'LIKE' mysql expression

Sounds like you want IN rather than LIKE - you can use the query builder to do that - something like this...

$cities=$em->getRepository('AppBundle:Cities');
$qb=$cities->createQueryBuilder('c');

$qb->where($qb->expr()->in('c.stateId', $dataState));
$query=$qb->query();

$result=$query->getResult();

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