/** * Updates an existing State 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 StateSearch(); $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['State']; $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]); } }
/** * Lists all State models. * @return mixed */ public function actionIndex() { $searchModel = new StateSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }