Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine ORM Criteria - dynamic orX

I spent a long time on that but can't find proper solution. How to amend code below so I could use a variable number of dynamic contains conditions?

$criteria = Criteria::create();
$expr = Criteria::expr();

$criteria->where(
            $expr->orX(
                    $expr->contains('field1', $str),
                    $expr->contains('field2', $str),
                    $expr->contains('field3', $str),
                    $expr->contains('field4', $str)
            )
    );
like image 911
GrumpyHat Avatar asked Oct 01 '22 16:10

GrumpyHat


1 Answers

You can call it dynamicly like this:

$criteria = new Criteria();
$expr = array();
$expr[] = $criteria->expr()->eq(/** what you want */);
$expr[] = $criteria->expr()->contains(/** what you want */);
$criteria->where(call_user_func_array(array( $criteria->expr(), 'orX' ),$expr));
like image 185
Stefan Sensz Avatar answered Oct 03 '22 22:10

Stefan Sensz