From f24984de285e890354a3195bd6203ee90cc4dce4 Mon Sep 17 00:00:00 2001 From: Eremin Michael Date: Mon, 13 Aug 2018 10:50:19 +0500 Subject: [PATCH] Add `exportColumns` to config --- components/Crud.php | 2 +- components/CrudImport.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/Crud.php b/components/Crud.php index eadee7d..f4bd951 100644 --- a/components/Crud.php +++ b/components/Crud.php @@ -1062,7 +1062,7 @@ public function export(CrudExportForm $model) 'renderData' => (bool)$model->renderData, 'model' => $this->getModel('search'), 'dataProvider' => $this->getDataProvider(), - 'columns' => $this->guessColumns($this->getFields()), + 'columns' => $this->getConfig('exportColumns', $this->guessColumns($this->getFields())), ]); return $exporter->export(); } diff --git a/components/CrudImport.php b/components/CrudImport.php index 2e0bdb6..be7caf7 100644 --- a/components/CrudImport.php +++ b/components/CrudImport.php @@ -9,6 +9,7 @@ use Yii; use yii\base\BaseObject; use yii\db\Schema; +use yii\helpers\ArrayHelper; /** * Class CrudImport @@ -108,6 +109,10 @@ public function import() /* @var $model \yii\db\ActiveRecord */ $model = new $this->modelClass; + if ($id = ArrayHelper::getValue($values, 'id')) { + $model->id = $id; + $model->setIsNewRecord(false); + } $model->setAttributes($values); if ($model->save()) {