<span style="font-size:18px;">/*
*action 批量入库
*$arr 必须是二维数组
*
*/
function many_file($file)
{
//echo count($file);die;
$arr = array();
foreach($file as $k=>$v)
{
$img = $v->name;
$images = 'uploads/'.$img;
$arr[]['images'] = $images;
}
$connection = \Yii::$app->db;
//数据批量入库
return $connection->createCommand()->batchInsert(
'manyfile',
['images'],
$arr
)->execute();
}</span>
或者
<span style="font-size:18px;">$model = new User();
foreach($data as $attributes)
{
$_model = clone $model;
$_model->setAttributes($attributes);
$_model->save();
}
</span>
还可以
<span style="font-size:18px;">$model = new User();
foreach($data as $attributes)
{
$model->isNewRecord = true;
$model->setAttributes($attributes);
$model->save() && $model->id=0;
}
</span>