Suggest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace common\models;
  3. use common\behaviors\CommentBehavior;
  4. use common\modules\user\models\User;
  5. use Yii;
  6. use yii\behaviors\BlameableBehavior;
  7. use yii\behaviors\TimestampBehavior;
  8. /**
  9. * This is the model class for table "{{%suggest}}".
  10. *
  11. * @property integer $id
  12. * @property string $title
  13. * @property string $content
  14. * @property integer $created_at
  15. * @property integer $user_id
  16. */
  17. class Suggest extends \yii\db\ActiveRecord
  18. {
  19. /**
  20. * @inheritdoc
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%suggest}}';
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['title', 'content'], 'required'],
  33. [['user_id'], 'integer'],
  34. [['title'], 'string', 'max' => 128],
  35. [['content'], 'string', 'max' => 1000],
  36. ];
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'title' => '标题',
  46. 'content' => '内容',
  47. 'created_at' => '发布于',
  48. 'user_id' => '用户',
  49. ];
  50. }
  51. public function behaviors()
  52. {
  53. return [
  54. [
  55. 'class' => TimestampBehavior::className(),
  56. 'updatedAtAttribute' => false,
  57. ],
  58. [
  59. 'class' => BlameableBehavior::className(),
  60. 'createdByAttribute' => 'user_id',
  61. 'updatedByAttribute' => false,
  62. ],
  63. // [
  64. // 'class' => CommentBehavior::className()
  65. // ],
  66. ];
  67. }
  68. public function getUser()
  69. {
  70. return $this->hasOne(User::className(), ['id' => 'user_id']);
  71. }
  72. }