ArticleCategory.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%ARTICLE_CATEGORY}}".
  6. *
  7. * @property string $ID
  8. * @property string $CATE_NAME 分类名
  9. * @property int $SORT
  10. * @property int $STATUS 状态
  11. * @property int $CREATED_AT 创建时间
  12. */
  13. class ArticleCategory extends \common\components\ActiveRecord
  14. {
  15. /**
  16. * @inheritdoc
  17. */
  18. public static function tableName()
  19. {
  20. return '{{%ARTICLE_CATEGORY}}';
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['CATE_NAME', 'CREATED_AT'], 'required'],
  29. [['SORT', 'STATUS', 'CREATED_AT'], 'integer'],
  30. [['ID'], 'string', 'max' => 32],
  31. [['CATE_NAME'], 'string', 'max' => 20],
  32. [['CATE_NAME'], 'unique'],
  33. [['ID'], 'unique'],
  34. ];
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'ID' => 'ID',
  43. 'CATE_NAME' => Yii::t('app', 'category'),
  44. 'STATUS' => Yii::t('app', 'status'),
  45. 'SORT' => Yii::t('app', 'sort'),
  46. 'CREATED_AT' => Yii::t('app', 'createAt'),
  47. ];
  48. }
  49. /**
  50. * 获取全部分类
  51. * @return array|\yii\db\ActiveRecord[]
  52. */
  53. public static function getAllCategory(){
  54. return ArticleCategory::find()->where('STATUS=1')->indexBy('ID')->orderBy('SORT ASC')->asArray()->all();
  55. }
  56. }