예제 #1
0
 public function subscribes()
 {
     $email = \Yii::$app->request->get('subscribe_email');
     if (isset($email)) {
         $key = md5(microtime());
         $subscribes = new Subscribes();
         $subscribes->email = $email;
         $subscribes->key = $key;
         $subscribes->status = 0;
         if ($subscribes->save()) {
             $link = $_SERVER['SERVER_NAME'] . '/?confirm=' . $key;
             //                $message = 'hello your link <a href="http://' . $link . '">' . $link . '</a>';
             //
             //                Yii::$app->mailer->compose()
             //                    ->setFrom('*****@*****.**')
             //                    ->setTo($email)
             //                    ->setSubject('Confirmation subscribes')
             //                    ->setHtmlBody($message)
             //                    ->send();
             \Yii::$app->getSession()->setFlash('subscribe_success', 'Дякуємо! Ваш email додано до нашої розсилки');
         } else {
             \Yii::$app->getSession()->setFlash('subscribe_error', $subscribes->errors['email']['0']);
         }
     }
     $confirm = \Yii::$app->request->get('confirm');
     if (isset($confirm)) {
         $model = Subscribes::findOne(['key' => $confirm]);
         $model->status = 1;
         $model->save();
     }
     return true;
     //Yii::$app->controller->goBack();
     //Yii::$app->response->getHeaders()->set('X-Pjax-Url: ' . Yii::$app->request->referrer);
     //return $this->redirect(Yii::$app->request->referrer);
 }
예제 #2
0
 /**
  * Finds the Subscribes model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Subscribes the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Subscribes::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }