/** * Creates a new ContentMenu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ContentMenu(); $model->status = 'on'; $remove_model = ContentMenu::find()->where(['status' => 'on'])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($remove_model) { foreach ($remove_model as $rem_model) { $rem_model->status = 'off'; $rem_model->save(); } } return $this->redirect('/content-menu'); } else { return $this->render('create', ['model' => $model]); } }