Skip to content

Instantly share code, notes, and snippets.

@DBasic
Last active August 29, 2015 13:57
Show Gist options
  • Save DBasic/9376908 to your computer and use it in GitHub Desktop.
Save DBasic/9376908 to your computer and use it in GitHub Desktop.
Yii # actionBatchUpdate method
public function actionBatchUpdate()
{
// retrieve items to be updated in a batch mode
// assuming each item is of model class 'Item'
$items=$this->getItemsToUpdate();
if(isset($_POST['Item']))
{
$valid=true;
foreach($items as $i=>$item)
{
if(isset($_POST['Item'][$i]))
$item->attributes=$_POST['Item'][$i];
$valid=$item->validate() && $valid;
}
if($valid) // all items are valid
// ...do something here
}
// displays the view to collect tabular input
$this->render('batchUpdate',array('items'=>$items));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment