Search code examples
zend-framework2

How to make multiple where->like() with Zend Framework 2?


I tried making a nest on a :

$where = new Where();

I also tried making multiple :

$where->like

Could someone please provide me an example of how I can make multiple like ? I would like to search two different fields with the same value %$value%

Thank you and best regards


Solution

  • Within the Where object you can NEST (wrap in parenthesis) your options and specify an operator (in this case, OR):

    $where = new Where();
    $where->NEST
        ->like('field1', '%value%')
        ->OR
        ->like('field2', '%value%')
        ->UNNEST;
    

    This will generate:

    ... WHERE (`field1` LIKE '%value%' OR `field2` LIKE '%value%')