Category.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace addons\StarChain\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_star_chain_category}}".
  6. *
  7. * @property int $id
  8. * @property int|null $category_id 分类ID
  9. * @property int|null $pid
  10. * @property string|null $name 分类名称
  11. * @property int|null $sort 排序
  12. * @property int|null $level 分类层级,从0开始
  13. * @property int|null $created_at
  14. * @property int|null $updated_at
  15. */
  16. class Category extends BaseModel
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_star_chain_category}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['sort', 'level', 'created_at', 'updated_at'], 'integer'],
  32. [['category_id', 'pid'], 'max' => 64],
  33. [['name'], 'string', 'max' => 255],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'category_id' => 'Category ID',
  44. 'pid' => 'Pid',
  45. 'name' => 'Name',
  46. 'sort' => 'Sort',
  47. 'level' => 'Level',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. ];
  51. }
  52. /**
  53. * 获取分类名称
  54. *
  55. * @param string $category_id
  56. * @return string
  57. */
  58. public static function getCategoryName($category_id)
  59. {
  60. return self::find()->where(compact('category_id'))->select('name')->scalar();
  61. }
  62. }