Created
June 25, 2012 11:24
-
-
Save hugodotlau/2988041 to your computer and use it in GitHub Desktop.
Yii 批量更新范例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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