Skip to content

Commit

Permalink
Fix article publish_date bug after validation fail (better way)
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
keshikashviligio committed Jan 16, 2017
1 parent 22c3d1f commit 47e53bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 3 additions & 0 deletions models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 0 additions & 4 deletions models/TranslatableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 47e53bd

Please sign in to comment.