From 47e53bddca018ec80bdc0738f7c67ba784f62f84 Mon Sep 17 00:00:00 2001 From: koco Date: Mon, 16 Jan 2017 17:55:33 +0400 Subject: [PATCH] Fix article publish_date bug after validation fail (better way) Fixes #12 --- models/Article.php | 3 +++ models/TranslatableModel.php | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/models/Article.php b/models/Article.php index 8d1528a..4f4c0a5 100644 --- a/models/Article.php +++ b/models/Article.php @@ -129,6 +129,9 @@ public function rules() [['category_id'], 'required'], [['slug'], 'unique'], [['published_at'], 'default', 'value' => time()], + [['published_at'], 'filter', 'filter' => 'strtotime', 'when' => function($model) { + return is_string($model->published_at); + }], [['category_id'], 'exist', 'targetClass' => ArticleCategory::className(), 'targetAttribute' => 'id'], [['author_id', 'updater_id', 'position', 'status'], 'integer'], [['slug', 'thumbnail_base_url', 'thumbnail_path', 'url'], 'string', 'max' => 2024], diff --git a/models/TranslatableModel.php b/models/TranslatableModel.php index db26753..fccbbe2 100644 --- a/models/TranslatableModel.php +++ b/models/TranslatableModel.php @@ -59,10 +59,6 @@ public function load($postData, $formName = null) return false; } - if($this->hasAttribute('published_at')){ - $this->published_at = $this->published_at ? strtotime($this->published_at) : time(); - } - $className = \yii\helpers\StringHelper::basename(static::$translateModel); $translations = ArrayHelper::getValue($postData, $className); $this->newTranslations = [];