TimestampBehavior::className(), // 'attributes' => [ // # 创建之前 // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'], // # 修改之前 // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at'] // ], // #设置默认值 // 'value' => $_SERVER['REQUEST_TIME'] // ] // ]; // } public function rules() { return [ ['name','required','message'=>'不能为空'], ['img','string','max'=>40], ['name','string','min'=>2,'max'=>20,'message'=>'请输入正确的城市名称'], ['name', 'unique', 'targetClass' => 'common\models\CategoryFacilities','on'=>['add'],'message'=>'名称已经存在'], ]; } /* * 调用里面的验证,错误返回数组,正确返回对象 * */ public function Authenticator($input) { $this->load($input,''); if(!$this->validate()) return $this->errors; return $this; } public function FindById($id) { return self::findOne($id); } public function getList($page,$arr = []) { $query = self::find(); $query->select($arr); $query = $this->WhereColumn($query); if(!empty($page['page'])) { $query->offset = ($page['page'] - 1) * $page['limit']; $query->limit = $page['limit']; } return $query->orderBy(['sort'=>SORT_DESC,'create_at'=>SORT_DESC])->asArray()->all(); } private function WhereColumn($query) { $query->andFilterWhere(['name'=>$this->name]); $query->andWhere(['del'=>$this->setDel]); return $query; } public function Total() { $query = self::find(); $query = $this->WhereColumn($query); return $query->count(); } }