/** * Batch insert values into the table. * @param array $values The values to be inserted. * @param array $options Additional attribute for the query class. * @return mixed */ public static function batchInsert($values, $options = []) { $inserts = array_map(function ($model) { if ($model instanceof ActiveRecord) { return $model->getAttributes(); } else { if (is_array($model)) { return $model; } } }, $values); return Command::batchExecute(self::getDb()->createCommand()->batchPutAllItems(static::tableName(), $inserts, $options)); }
/** * Creates a command for execution. * @param array $config The configuration for the Command class. * @return Command the DB command */ public function createCommand(array $config = []) { $command = Yii::createObject(array_merge($config, ['class' => Command::className(), 'db' => $this])); return $command; }