From e3b940f2bf1ee463a3f4ad100e466180679deb96 Mon Sep 17 00:00:00 2001 From: githubjeka Date: Tue, 29 Jan 2019 14:23:04 +0300 Subject: [PATCH] Fix #16 --- src/controllers/ItemController.php | 2 +- src/models/ItemForm.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/ItemController.php b/src/controllers/ItemController.php index 11c83bd..b5a9a31 100644 --- a/src/controllers/ItemController.php +++ b/src/controllers/ItemController.php @@ -82,7 +82,7 @@ public function actionSave() { $item = null; - if (isset($_POST['ItemForm']['oldName'])) { + if (isset($_POST['ItemForm']['oldName']) && $_POST['ItemForm']['oldName'] !== '') { $item = $this->findItem($_POST['ItemForm']['oldName']); } diff --git a/src/models/ItemForm.php b/src/models/ItemForm.php index 52de170..9d31b94 100644 --- a/src/models/ItemForm.php +++ b/src/models/ItemForm.php @@ -76,14 +76,14 @@ public function rules() [['name', 'type'], 'required'], [ ['name'], - 'unique', + 'uniqueName', 'when' => function () { return $this->isNewRecord; } ], [ ['oldName'], - 'unique', + 'uniqueName', 'when' => function () { return !$this->isNewRecord && $this->name != $this->oldName; } @@ -94,7 +94,7 @@ public function rules() ]; } - public function unique() + public function uniqueName() { $authManager = Yii::$app->authManager; $value = $this->name;