Skip to content

Instantly share code, notes, and snippets.

@hugodotlau
Created June 25, 2012 11:24
Show Gist options
  • Save hugodotlau/2988041 to your computer and use it in GitHub Desktop.
Save hugodotlau/2988041 to your computer and use it in GitHub Desktop.
Yii 批量更新范例
<?php
public function actionBatchUpdate($id)
{
$model = Product::model()->findByPk($id);
$items=Retailprice::model()->findAllByAttributes(array('product_id'=>$id));
if(isset($_POST['Retailprice']))
{
$valid=true;
foreach($items as $i=>$item)
{
if(isset($_POST['Retailprice'][$i]))
$item->attributes=$_POST['Retailprice'][$i];
$item->save();
$valid=$item->validate() && $valid;
}
if($valid) // all items are valid
$debug = "All good!";
//$debug = "All good!" . $_POST['Retailprice'];
}
// displays the view to collect tabular input
$debug =$item->attributes;
$this->render('batchupdate',array('debug'=>$debug, 'items'=>$items,'model'=>$model));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment