我想从手中保存我的数据。当我尝试保存数据时,Nothings错误。但我的handsontable数据无法插入我的数据库中。 这是我的代码
public function actionSavePricelist($id)
{
header("Content-Type: application/json");
if(!Yii::app()->request->isPostRequest)
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
$user = Yii::app()->session['loginSession']['userId'];
$model=$this->loadModel($id);
$vendor_price= json_decode($_POST['price_list']);
$flagError=0;
for($i=0;$i<count($vendor_price->data);$i++) {
$row = $vendor_price->data[$i];
if($row[0] == null && $row[1] == null) continue;
else {
if(!isset($row[3])){
$mVenPri = new MstVendorPricelist;
$idcity = MstCity::model()->findByAttributes(array(
'city_name' => $row[1]
)
);
$idc = $idcity->city_id;
$mVenPri->item_id=$row[3];
$mVenPri->vendor_id=$model->vendor_id;
$mVenPri->city_id=$idc;
$mVenPri->price=$row[2];
$mVenPri->created_date=date('Y-m-d H:i:s');
$mVenPri->created_by=$user;
$mVenPri->modified_date=date('Y-m-d H:i:s');
$mVenPri->modified_by=$user;
if(!$mVenPri->save())
$flagError++;
} else {
$modelprice=MstVendorPriceList::model()->findByPk($id);
$idcity = MstCity::model()->findByAttributes(array(
'city_name' => $row[1])
);
$idc = $idcity->city_id;
$modelprice->item_id=$row[3];
$modelprice->vendor_id=$model->vendor_id;
$modelprice->city_id=$idc;
$modelprice->price=$row[2];
$modelprice->created_date=date('Y-m-d H:i:s');
$modelprice->created_by=$user;
$modelprice->modified_date=date('Y-m-d H:i:s');
$modelprice->modified_by=$user;
if(!$modelprice->save())
$flagError++;
}
}
}
if($flagError == 0)
echo CJSON::encode(array('success'=>true,'msg'=>'You have successfully added data.'));
else
echo CJSON::encode(array('msg'=>'Error occurred during inserting details.'));
// var_dump($vendor_price);
}
实际上这个功能是更新但是,类似于保存数据。更新我的供应商并从掌上电脑保存新数据。 请帮我。我的代码有什么问题