yiiyii1.x

How to use two criteria in a query?


Well i need to add another criteria that adds to the first one.

What's the best way to do it?

 $criteria = new CDbCriteria();
 $criteria->with = [
    'user',
    'product',
    'product.store',
    'product.store.client' => ['together' => true],
  ];
  $offset = intval($_GET['start']);
  $criteria->offset = $offset;
  $criteria->limit = intval($_GET['length']) + 10;
  $criteria->addCondition('closed_date is null');

Solution

  • By using addCondition as you have already done. The 2nd parameter is the operator which is default set to and.

    https://www.yiiframework.com/doc/api/1.1/CDbCriteria#addCondition-detail

    so something like this:

    $criteria->addCondition('product.store is null', 'or');
    

    of course you could also use other function like addColumnCondition addInCondition etc. or

    $criteria->compare('product.store', 'store name', true);