/** * Creates a new Subscribing model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Subscribing(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Get a subscribing form * @return array Data */ public static function getSubscribingForm() { $model = new Subscribing(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (!$model->save()) { $errors = $model->getErrors(); $errorMessage = array_shift($errors); Yii::$app->getSession()->setFlash('error-subscribe', 'Произошла ошибка: ' . $errorMessage); } Yii::$app->getSession()->setFlash('success-subscribe', 'Вы успешно подписались на новостную рассылку от dynamomania.com'); return Yii::$app->getResponse()->redirect(Url::to('/')); } $block = ['view' => '@frontend/views/forms/subscribing_form', 'data' => compact('model')]; return $block; }