Skip to content

Instantly share code, notes, and snippets.

@mstaack
Last active December 16, 2015 10:32
Show Gist options
  • Save mstaack/48f59ea3d7ed0f916b2b to your computer and use it in GitHub Desktop.
Save mstaack/48f59ea3d7ed0f916b2b to your computer and use it in GitHub Desktop.
Create Criteria From fields and values
private function getCriteriaForRow($row)
{
$fullCriteria = new CDbCriteria();
foreach ($this->mapping as $uploadColumn => $databaseColumn) {
$value = $row[array_search($uploadColumn, $this->fileHeader)];
$criteria = new CDbCriteria();
$criteria->condition = $databaseColumn . '=:' . $databaseColumn;
$criteria->params = [':' . $databaseColumn => $value];
$fullCriteria->mergeWith($criteria, $operator = 'AND');
}
return $fullCriteria;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment