[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => [], 'allow' => true, 'roles' => ['@'], ], ], ], ]; } /** * 列表 * @return string */ public function actionIndex() { $search = Yii::$app->request->get(); $models = Area::find()->where(['type'=>2]); if(!empty($search['province'])) $models->andWhere("father_area_id = :father_area_id",[':father_area_id'=>$search['province']]); if(!empty($search['display'])) $models->andWhere("display = :display",[':display'=>$search['display']]); if(!empty($search['name'])) $models->andWhere("area like :name",[':name'=>"%".$search['name']."%"]); $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]); $models = $models->offset($pages->offset)->limit($pages->limit)->orderBy("ishot DESC")->all(); return $this->render('index', ['models' => $models, 'pages' => $pages,'name'=>'城市管理','search'=>$search]); } /** * 更新状态 * @return string */ public function actionUpdateStatus() { $id = Yii::$app->request->post('id'); $model = Area::find()->where(['id'=>$id])->one(); if($model->display==Area::DISPLAY_YES) $model->display = Area::DISPLAY_NO; else $model->display = Area::DISPLAY_YES; if($model->save()) $result = ['sign'=>1,'msg'=>'修改状态成功']; else $result = ['sign'=>0,'msg'=>'修改状态失败']; return json_encode($result); } }