保存后ID等于batchInsert中的null
$model= new Sale();
if($model->load(Yii::$app->request->post())) {
$model->status=1;
$model->price = str_replace(",","",$model->price);
//$id = $model->id
$model->save();
$id = $model->id;
if($model->pardakht == 1) {
for($i=0;$i<$model->count;$i++) {
$data[$i][0]=Yii::$app->request->post('number_check')[$i];
$data[$i][1]=Yii::$app->request->post('price_check')[$i];
$data[$i][2]=Yii::$app->request->post('date_check')[$i];
$data[$i][3]=Yii::$id;
$data[$i][4]=Yii::$model->customer_id;
}
Yii::$app->db->creatCommand()->batchInsert('sale_check', [
'number_check',
'price_check',
'date_check',
'user_id',
'customer_id'
], $data)->execute();
}
}
var_dump($id);
$id = null ????????????
你的模型有错误,要找出问题出在哪里以及哪些属性有错误, 改变这个:
$model->save();
$id = $model->id;
到
if($model->save()) {
$id = $model->id;
/** other codes ****/
}else{
var_dump($model->errors);
/** or other usage of this array result **/
}