request->getIsPost()) { throw new MethodNotAllowedHttpException(); } $id = (int)$id; $result = null; if (empty($this->modelClass) || !class_exists($this->modelClass)) { throw new InvalidConfigException("Model class doesn't exist"); } /* @var $modelClass ActiveRecord */ $modelClass = $this->modelClass; $attribute = $this->attribute; $model = $modelClass::find()->where([$this->primaryKey => $id]); if (!empty($this->andWhere)) { $model->andWhere($this->andWhere); } $model = $model->one(); if (!is_null($this->scenario)) { $model->scenario = $this->scenario; } if (!$model->hasAttribute($this->attribute)) { throw new InvalidConfigException("Attribute doesn't exist"); } if ($model->$attribute == $this->onValue) { $model->$attribute = $this->offValue; } elseif ($this->onValue instanceof Expression && $model->$attribute != $this->offValue) { $model->$attribute = $this->offValue; } else { $model->$attribute = $this->onValue; } if ($model->save()) { if ($this->setFlash) { Yii::$app->session->setFlash('success', $this->flashSuccess); } } else { if ($this->setFlash) { Yii::$app->session->setFlash('error', $this->flashError); } } if (Yii::$app->request->getIsAjax()) { Yii::$app->end(); } /* @var $controller \yii\web\Controller */ $controller = $this->controller; if (!empty($this->redirect)) { return $controller->redirect($this->redirect); } return $controller->redirect(Yii::$app->request->getReferrer()); } }