/**
  * Lists all City models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new CitySearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
示例#2
0
 /**
  * Updates an existing City model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $searchModel = new CitySearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         $model->attributes = $_POST['City'];
         $model->updated_by = Yii::$app->getid->getId();
         $model->updated_at = new \yii\db\Expression('NOW()');
         if ($model->save()) {
             return $this->redirect(['index']);
         } else {
             return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
         }
     } else {
         return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     }
 }