示例#1
0
 /**
  * Creates a new Subscribes model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Subscribes();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 public function subscribe()
 {
     if (Request::isMethod('post') && Input::get('email')) {
         $email = strip_tags(addslashes(Input::get('email')));
         $exist = Subscribes::where('email', '=', $email)->count();
         if ($exist == 0) {
             $rules = ['email' => 'required|email'];
             $validator = Validator::make(Input::all(), $rules);
             if ($validator->fails()) {
                 $messages = $validator->messages();
                 return Redirect::to('/')->withErrors($messages)->withInput();
             }
             $ussubscribe = new Subscribes();
             $ussubscribe->email = $email;
             $ussubscribe->date = date('Y-m-d H:i:s');
             $ussubscribe->save();
             return Redirect::to('/')->with('message', 'Sikeresen felíratkozoztt hírlevelünkre');
         } else {
             return Redirect::to('/')->with('message', 'Már korábban felíratkozoztt hírlevelünkre');
         }
     } else {
         return Redirect::to('/')->with('message', 'Sikertelen hírlevél feliratkozás')->withInput();
     }
 }
示例#3
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);
 }