Comment.php 763 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 2017/3/8
  6. * Time: 下午11:21
  7. */
  8. namespace api\modules\v1\models;
  9. use api\common\models\User;
  10. use common\helpers\Util;
  11. use yii\helpers\ArrayHelper;
  12. class Comment extends \common\models\Comment
  13. {
  14. public function getAuthor()
  15. {
  16. return $this->hasOne(User::className(), ['id' => 'user_id']);
  17. }
  18. public function fields()
  19. {
  20. return ArrayHelper::merge(parent::fields(), [
  21. 'author',
  22. 'created_at' => function ($model) {
  23. /* @var self $model */
  24. return Util::formatTime($model->created_at);
  25. },
  26. ]);
  27. }
  28. public function extraFields()
  29. {
  30. return [
  31. 'sons'
  32. ];
  33. }
  34. }