Skip to content

Instantly share code, notes, and snippets.

@speedygfw
Created August 1, 2012 08:41
Show Gist options
  • Save speedygfw/3225082 to your computer and use it in GitHub Desktop.
Save speedygfw/3225082 to your computer and use it in GitHub Desktop.
Validate multiple Models in Yii (generic)
<?php
/**
* validateModels
* @param array $models
* @return boolean $valid
*/
function validateModels(array $models)
{
$valid = true;
foreach ($models as $key => $model) {
$models[$key]->attributes = $_POST[get_class($model)][$key];
$valid = $model->validate() && $valid;
}
return $valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment