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.

120 lines
2.7 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. public static function columns()
  61. {
  62. return [
  63. [
  64. 'class' => 'blobt\grid\CheckboxColumn',
  65. 'width' => '2%',
  66. 'align' => 'center'
  67. ],
  68. [
  69. 'attribute' => 'id',
  70. 'width' => '5%',
  71. 'align' => 'center'
  72. ],
  73. [
  74. 'attribute' => 'created_at',
  75. 'width' => '7%',
  76. 'format' => 'date'
  77. ],
  78. [
  79. 'attribute' => 'cat_name',
  80. 'width' => '13%',
  81. ],
  82. [
  83. 'attribute' => 'icon',
  84. 'width' => '5%',
  85. ],
  86. [
  87. 'attribute' => 'icon_type',
  88. 'width' => '7%',
  89. 'showConstText' => true
  90. ],
  91. [
  92. 'attribute' => 'description',
  93. 'enableSorting' => false,
  94. 'format' => 'ntext',
  95. 'width' => '50%',
  96. ],
  97. [
  98. 'class' => 'iron\grid\ActionColumn',
  99. 'align' => 'center',
  100. ],
  101. ];
  102. }
  103. public function behaviors()
  104. {
  105. return [
  106. TimestampBehavior::className()
  107. ];
  108. }
  109. }