Carousel.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace common\models;
  3. use common\behaviors\CacheInvalidateBehavior;
  4. use Yii;
  5. use yii\db\ActiveRecord;
  6. /**
  7. * This is the model class for table "carousel".
  8. *
  9. * @property integer $id
  10. * @property string $key
  11. * @property string $title
  12. * @property integer $status
  13. *
  14. * @property CarouselItem[] $items
  15. */
  16. class Carousel extends ActiveRecord
  17. {
  18. const STATUS_DRAFT = 0;
  19. const STATUS_ACTIVE = 1;
  20. /**
  21. * @inheritdoc
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%carousel}}';
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public function behaviors()
  31. {
  32. return [
  33. 'cacheInvalidate' => [
  34. 'class' => CacheInvalidateBehavior::className(),
  35. 'keys' => [
  36. function ($model) {
  37. return [
  38. self::className(),
  39. $model->key
  40. ];
  41. }
  42. ]
  43. ]
  44. ];
  45. }
  46. /**
  47. * @inheritdoc
  48. */
  49. public function rules()
  50. {
  51. return [
  52. [['key'], 'required'],
  53. [['key'], 'unique'],
  54. [['status'], 'integer'],
  55. [['key', 'title'], 'string', 'max' => 255]
  56. ];
  57. }
  58. /**
  59. * @inheritdoc
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'id' => Yii::t('common', 'ID'),
  65. 'key' => Yii::t('common', 'Key'),
  66. 'title' => '位置',
  67. 'status' => Yii::t('common', 'Active'),
  68. ];
  69. }
  70. /**
  71. * @return \yii\db\ActiveQuery
  72. */
  73. public function getItems()
  74. {
  75. return $this->hasMany(CarouselItem::className(), ['carousel_id' => 'id']);
  76. }
  77. }