UserNode.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 14:56
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class UserNode extends Common
  12. {
  13. // public function behaviors()
  14. // {
  15. // return [
  16. // [
  17. // 'class' => TimestampBehavior::className(),
  18. // 'attributes' => [
  19. // # 创建之前
  20. // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
  21. // # 修改之前
  22. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  23. // ],
  24. // #设置默认值
  25. // 'value' => $_SERVER['REQUEST_TIME']
  26. // ]
  27. // ];
  28. // }
  29. public function rules()
  30. {
  31. return [
  32. ['controller','required','message'=>'控制器不能为空'],
  33. ['action','required','message'=>'控制器方法不能为空'],
  34. ['describe','string','max'=>200]
  35. ];
  36. }
  37. public function FindById($id)
  38. {
  39. return self::findOne($id);
  40. }
  41. public function MultipleCondition()
  42. {
  43. return self::find()->andFilterWhere(['controller'=>$this->controller])
  44. ->andFilterWhere(['action'=>$this->action])
  45. ->one();
  46. }
  47. public function getList($input)
  48. {
  49. $query = self::find();
  50. if(!empty($input['page']))
  51. {
  52. $query->offset = ($input['page'] -1) * $input['limit'];
  53. $query->limit = $input['limit'];
  54. }
  55. $row['count'] = $query->count();
  56. $row['data'] = $query->orderBy('controller,create_at')->asArray()->all();
  57. return $row;
  58. }
  59. public function Check($input)
  60. {
  61. $this->load($input,'');
  62. if(!$this->validate())
  63. {
  64. return $this->errors;
  65. }
  66. return $this;
  67. }
  68. }