You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.8 KiB

  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. /**
  6. * This is the model class for table "category".
  7. *
  8. * @property int $id
  9. * @property string $cat_name
  10. * @property string $icon
  11. * @property int $icon_type
  12. * @property string $description
  13. * @property int $sort_order
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class Category extends \yii\db\ActiveRecord
  18. {
  19. const ICON_TYPE_BOOSTARAP = 1;
  20. const ICON_TYPE_AWESOME = 2;
  21. public static $iconType = [
  22. self::ICON_TYPE_BOOSTARAP => "boostrap",
  23. self::ICON_TYPE_AWESOME => "awesome"
  24. ];
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return 'category';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['icon_type', 'cat_name', 'created_at'], 'required'],
  39. [['icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'],
  40. [['description'], 'string'],
  41. [['cat_name', 'icon'], 'string', 'max' => 64],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'cat_name' => '类名',
  52. 'icon' => 'Icon',
  53. 'icon_type' => '图标类型',
  54. 'description' => '描述',
  55. 'sort_order' => 'Sort Order',
  56. 'created_at' => '添加日期',
  57. 'updated_at' => 'Updated At',
  58. ];
  59. }
  60. /**
  61. * @return array
  62. * 列格式
  63. */
  64. public static function columns()
  65. {
  66. return [
  67. [
  68. 'class' => 'blobt\grid\CheckboxColumn',
  69. 'width' => '2%',
  70. 'align' => 'center'
  71. ],
  72. [
  73. 'attribute' => 'id',
  74. 'width' => '5%',
  75. 'align' => 'center'
  76. ],
  77. [
  78. 'attribute' => 'created_at',
  79. 'width' => '7%',
  80. 'format' => 'date'
  81. ],
  82. [
  83. 'attribute' => 'cat_name',
  84. 'width' => '13%',
  85. ],
  86. [
  87. 'attribute' => 'icon',
  88. 'width' => '5%',
  89. ],
  90. [
  91. 'attribute' => 'icon_type',
  92. 'width' => '7%',
  93. 'showConstText' => true
  94. ],
  95. [
  96. 'attribute' => 'description',
  97. 'enableSorting' => false,
  98. 'format' => 'ntext',
  99. 'width' => '50%',
  100. ],
  101. [
  102. 'class' => 'iron\grid\ActionColumn',
  103. 'align' => 'center',
  104. ],
  105. ];
  106. }
  107. public function behaviors()
  108. {
  109. return [
  110. TimestampBehavior::className()
  111. ];
  112. }
  113. }