$criteria1 = new CDbCriteria(array( 'select' => 'id, name', 'condition' => 'status=:status', 'params' => array(':status' => 1), )); $criteria2 = new CDbCriteria(array( 'select' => 'age, address', 'condition' => 'gender=:gender', 'params' => array(':gender' => 'male'), )); $criteria1->mergeWith($criteria2);
$criteria1 = new CDbCriteria(array( 'select' => 'id, name, age', 'condition' => 'status=:status', 'params' => array(':status' => 1), )); $criteria2 = array( 'condition' => 'gender=:gender', 'params' => array(':gender' => 'male'), ); $criteria1->mergeWith($criteria2);This code will merge the CDbCriteria instance with an array of condition and parameters. In summary, the Yii framework’s CDbCriteria mergeWith() method is used to merge two CDbCriteria instances or an instance with arrays of condition and parameters to build complex query criteria.