Пример #1
0
 /**
  * Creates a new College model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new College();
     $addressmodel = new Address();
     $contactmodel = new Contacts();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $image_logo = UploadedFile::getInstance($model, 'logo');
         $image_banner = UploadedFile::getInstance($model, 'banner');
         $model->logo = $image_logo->name;
         $ext_logo = end(explode('.', $image_logo));
         $ext_banner = end(explode('.', $image_banner));
         $rndstrngLogo = Yii::$app->security->generateRandomString('32') . "." . $ext_logo;
         $rndstrngBanner = Yii::$app->security->generateRandomString('32') . "." . $ext_banner;
         $path = Yii::$app->basePath . '/uploads/';
         $model->logo = 'backend/uploads/' . $rndstrngLogo;
         $model->banner = 'backend/uploads/' . $rndstrngBanner;
         $model->establish = $_POST['College']['establish'];
         $model->created = new Expression('NOW()');
         $addressmodel->address = $_POST['Address']['address'];
         $addressmodel->landmark = $_POST['Address']['landmark'];
         $addressmodel->country_id = $_POST['Address']['country_id'];
         $addressmodel->state_id = $_POST['Address']['state_id'];
         $addressmodel->city_id = $_POST['Address']['city_id'];
         $addressmodel->pincode = $_POST['Address']['pincode'];
         $addressmodel->created = new Expression('NOW()');
         $contactmodel->email = $_POST['Contacts']['email'];
         $contactmodel->landline = $_POST['Contacts']['landline'];
         $contactmodel->mobile = $_POST['Contacts']['mobile'];
         $contactmodel->created = new Expression('NOW()');
         $contactmodel->fax = $_POST['Contacts']['fax'];
         $contactmodel->status = $_POST['College']['status'];
         if ($model->save()) {
             $image_logo->saveAs($path . $rndstrngLogo);
             $image_banner->saveAs($path . $rndstrngBanner);
             $contactmodel->college_id = $model->id;
             $addressmodel->college_id = $model->id;
             if ($addressmodel->validate() && $contactmodel->validate()) {
                 $contactmodel->save();
                 $addressmodel->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new University model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $rootPath = str_replace(DIRECTORY_SEPARATOR . 'backend', "", Yii::$app->basePath);
     $img_move_to = $rootPath . '/frontend/web/images/uploads/';
     $model = new University();
     $addressmodel = new Address();
     $contactmodel = new Contacts();
     $implink = new ImportantLink();
     $downloadlink = new DownloadLink();
     if ($model->load(Yii::$app->request->post())) {
         $image_logo = UploadedFile::getInstance($model, 'logo');
         $image_banner = UploadedFile::getInstance($model, 'banner');
         $model->logo = $image_logo->name;
         $ext_logo = end(explode('.', $image_logo));
         $ext_banner = end(explode('.', $image_banner));
         $rndstrngLogo = Yii::$app->security->generateRandomString('32') . "." . $ext_logo;
         $rndstrngBanner = Yii::$app->security->generateRandomString('32') . "." . $ext_banner;
         $path = Yii::$app->basePath . '/uploads/';
         $model->logo = 'images/uploads/' . $rndstrngLogo;
         $model->banner = 'images/uploads/' . $rndstrngBanner;
         $model->establish = $_POST['University']['establish'];
         $model->created = new Expression('NOW()');
         $addressmodel->address = $_POST['Address']['address'];
         $addressmodel->landmark = $_POST['Address']['landmark'];
         $addressmodel->country_id = $_POST['Address']['country_id'];
         $addressmodel->state_id = $_POST['Address']['state_id'];
         $addressmodel->city_id = $_POST['Address']['city_id'];
         $addressmodel->pincode = $_POST['Address']['pincode'];
         $addressmodel->created = new Expression('NOW()');
         $contactmodel->email = $_POST['Contacts']['email'];
         $contactmodel->landline = $_POST['Contacts']['landline'];
         $contactmodel->mobile = $_POST['Contacts']['mobile'];
         $contactmodel->created = new Expression('NOW()');
         $contactmodel->fax = $_POST['Contacts']['fax'];
         //$contactmodel->status=$_POST['University']['status'];
         $implink->name = $_POST['ImportantLink']['name'];
         $implink->url = $_POST['ImportantLink']['url'];
         $downloadlink->name = $_POST['DownloadLink']['name'];
         $downloadlink->url = $_POST['DownloadLink']['url'];
         if ($model->save()) {
             $image_logo->saveAs($img_move_to . $rndstrngLogo);
             $image_banner->saveAs($img_move_to . $rndstrngBanner);
             $contactmodel->university_id = $model->id;
             $addressmodel->university_id = $model->id;
             $implink->university_id = $model->id;
             $downloadlink->university_id = $model->id;
             if ($addressmodel->validate() && $contactmodel->validate() && $downloadlink->validate() && $implink->validate()) {
                 $contactmodel->save();
                 $addressmodel->save();
                 $downloadlink->save();
                 $implink->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionEdit()
 {
     $id = \Yii::$app->request->get('id');
     $page = Contacts::find()->andWhere(['id' => $id])->one();
     $form = \Yii::$app->request->post('Contacts');
     if ($form) {
         $page->email = $form['email'];
         $page->phone = $form['phone'];
         $page->adress = $form['adress'];
         $page->map_long = $form['map_long'];
         $page->map_lat = $form['map_lat'];
         $page->save();
     }
     return $this->render('edit', ['item' => $page]);
 }
Пример #4
0
 public function actionAddContact()
 {
     $arrResult = [];
     $model = new Contacts();
     $model->ip = Yii::$app->user->id ? Yii::$app->user->id : Yii::$app->session->id;
     $model->user_id = Yii::$app->user->id ? Yii::$app->user->id : Yii::$app->session->id;
     $model->created_at = time();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $arrResult['success'] = 'Сообщение успешно отправленно!';
         return $arrResult;
     } else {
         $model->validate();
         vd($model->getFirstErrors());
         // ошибки
         if (Yii::$app->request->post('Contacts')['content'] == null) {
             $arrResult['error'] = 'Сообщение пусто!';
             return $arrResult;
         }
         if (Yii::$app->request->post('Contacts')['name'] == null) {
             $arrResult['error'] = 'Имя пусто!';
             return $arrResult;
         }
         if (Yii::$app->request->post('Contacts')['email'] == null) {
             $arrResult['error'] = 'email пусто!';
             return $arrResult;
         }
         if (Yii::$app->request->post('Contacts')['subject'] == null) {
             $arrResult['error'] = 'Тема  пуста!';
             return $arrResult;
         }
         $arrResult['error'] = 'Не коректный Email!';
         return $arrResult;
     }
 }
Пример #5
0
 public function getContact()
 {
     return $this->hasOne(Contacts::className(), ['university_id' => 'id']);
 }
Пример #6
0
 public function actionContacts()
 {
     return $this->render('contact', ['page' => Contacts::find()->where(['id' => 1])->one(), 'subjects' => ContactsSubjects::find()->all()]);
 }