Gru*_*Hat 5 php orm doctrine criteria doctrine-orm
我花了很长时间,但找不到合适的解决方案。如何修改下面的代码以便我可以使用可变数量的动态包含条件?
$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)
)
);
Run Code Online (Sandbox Code Playgroud)
您可以像这样动态调用它:
$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));
Run Code Online (Sandbox Code Playgroud)
小智 -1
你可以使用这个方法:
$criteria->where(Criteria::expr()->eq('active', 'true'));
Run Code Online (Sandbox Code Playgroud)