public function actionUnsubscribe() { $this->layout = 'unsubscribe-blank'; $model = new Subscribers(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($subscriber = Subscribers::find()->where(['email' => $model->email, 'isSubscribed' => '1'])->one()) { $subscriber->isSubscribed = '0'; if ($subscriber->update()) { Yii::$app->session->setFlash('success', 'Подписка отменена'); } } else { Yii::$app->session->setFlash('error', 'Вы не подписаны на рассылку'); } return $this->refresh(); } else { return $this->render('unsubscribe', ['model' => $model]); } }
/** * Finds the Subscribers model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Subscribers the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Subscribers::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }