Answer the question
In order to leave comments, you need to log in
Yii2 in the batchInsert command, for some reason, one empty record is created?
foreach($_POST[PostData] as $key => $value){
$str = strpos($key, "_");
$key = substr($key, 0, $str);
$postData->data_type = $key;
$postData->post_data = $value;
$postData->post_id;
$rows[] = [
'post_id' => $postData->post_id,
'data_type' => $postData->data_type,
'post_data' => $postData->post_data
];
}
array_shift($rows);
Yii::$app->db->createCommand()->batchInsert($postData::tableName(), ['post_id', 'data_type', 'post_data'], $rows)->execute();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question