/**
  * Creates a new Subscribers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Subscribers();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Subscribers model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Subscribers();
     if (isset($_GET['message'])) {
         $message = $_GET['message'];
     } else {
         $message = '';
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $emailtempaltemodel = EmailTemplates::find()->where(['email_key' => $model->type])->multilingual()->one();
         $admin_email = Configurations::find()->where(['key' => 'admin_email'])->one();
         Yii::$app->mailer->compose('subscribers-html', ['model' => $model, 'emailtempaltemodel' => $emailtempaltemodel])->setFrom($admin_email->value)->setTo($model->email)->setCc($admin_email->value)->setSubject($emailtempaltemodel->subject)->send();
         return $this->redirect(['create', 'message' => 'you are subscribed now']);
     } else {
         return $this->render('create', ['model' => $model, 'message' => $message]);
     }
 }
Exemplo n.º 3
0
 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]);
     }
 }