NavItem.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace common\models;
  3. use common\behaviors\PositionBehavior;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%nav_item}}".
  7. *
  8. * @property integer $id
  9. * @property string $title
  10. * @property string $url
  11. * @property integer $status
  12. */
  13. class NavItem extends \yii\db\ActiveRecord
  14. {
  15. /**
  16. * @inheritdoc
  17. */
  18. public static function tableName()
  19. {
  20. return '{{%nav_item}}';
  21. }
  22. /**
  23. * @inheritdoc
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['title', 'url'], 'required'],
  29. [['status', 'nav_id', 'order', 'target'], 'integer'],
  30. [['title', 'url'], 'string', 'max' => 128],
  31. ];
  32. }
  33. /**
  34. * @inheritdoc
  35. */
  36. public function attributeLabels()
  37. {
  38. return [
  39. 'id' => Yii::t('common', 'ID'),
  40. 'nav_id' => Yii::t('common', 'NAV ID'),
  41. 'title' => Yii::t('common', 'Title'),
  42. 'url' => Yii::t('common', 'Url'),
  43. 'target' => '是否新窗口打开',
  44. 'status' => Yii::t('common', 'Status'),
  45. 'order' => Yii::t('common', 'Order'),
  46. ];
  47. }
  48. public function attributeHints()
  49. {
  50. return [
  51. 'url' => '格式: /site/index a=1&b=2'
  52. ];
  53. }
  54. public function behaviors()
  55. {
  56. return [
  57. 'positionBehavior' => [
  58. 'class' => PositionBehavior::className(),
  59. 'positionAttribute' => 'order',
  60. 'groupAttributes' => [
  61. 'nav_id'
  62. ],
  63. ],
  64. ];
  65. }
  66. public function getNav()
  67. {
  68. return $this->hasOne(Nav::className(), ['id' => 'nav_id']);
  69. }
  70. }