Exemplo n.º 1
0
 protected function findModel($id)
 {
     if (($model = Map::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Страница не найдена.');
     }
 }
Exemplo n.º 2
0
 public function actionAjax($form)
 {
     switch ($form) {
         case 'call':
             $model = new CallForm();
             if (Yii::$app->request->isAjax) {
                 if ($model->load(Yii::$app->request->post()) && $model->sendAjaxForm(Yii::$app->params['adminEmail'])) {
                     $message = '<div><div class="alert alert-success">Ваше сообщение отправлено.</div></div>';
                     // TODO: Refactor
                     return $message;
                 } else {
                     return $this->renderPartial('call', ['model' => $model, 'form' => $form]);
                 }
             } else {
                 if ($model->load(Yii::$app->request->post()) && $model->sendAjaxForm(Yii::$app->params['adminEmail'])) {
                     Yii::$app->session->setFlash('contactFormSubmitted');
                     return $this->refresh();
                 } else {
                     return $this->render('call', ['model' => $model, 'form' => $form]);
                 }
             }
             break;
         case 'map':
             if (Yii::$app->request->isPost) {
                 $geoObject = Map::getPoints();
                 header('Content-Type: application/json');
                 return json_encode($geoObject);
             } else {
                 return $this->render('map');
             }
             break;
         default:
             throw new HttpException(404, 'Страница не найдена');
             break;
     }
 }