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)
)
);
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With