Ejemplo n.º 1
0
 public function actionIndex()
 {
     $mainpage = BMainpage::find()->where(['site' => 1])->one();
     $title_h1 = $mainpage->title_h1;
     $title_h2 = $mainpage->title_h2;
     $text_1 = $mainpage->text_1;
     $text_2 = $mainpage->text_2;
     $mainpageinterior = BInterior::find()->where(['site' => 1])->one();
     $images = $mainpageinterior->images;
     $masters = BMasters::find()->orderBy('sort')->all();
     $mastersforwomen = BMastersforwomen::find()->orderBy('sort')->all();
     $actions = BActions::find()->one();
     $BReviews = BReviews::find()->where('moderate = 1')->all();
     $sertificate = BSertificates::find()->where(['site' => 1])->one();
     return $this->render('index', ['title_h1' => $title_h1, 'text_1' => $text_1, 'title_h2' => $title_h2, 'text_2' => $text_2, 'masters' => $masters, 'mastersforwomen' => $mastersforwomen, 'sertificate' => $sertificate, 'images' => $images, 'actions' => $actions, 'reviews' => $BReviews]);
 }
Ejemplo n.º 2
0
 public function actionDeleteimages()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Yii::$app->user->loginUrl);
     }
     if ($_POST) {
         $new_array_images = array();
         for ($i = 0; $i < count($_POST['id_images']); $i++) {
             if ($_POST['delete_id_img'] != $_POST['id_images'][$i]) {
                 $new_array_images[] = $_POST['id_images'][$i];
             }
         }
         if ($_POST['page'] == 'interior') {
             $model = BInterior::find()->where(['site' => 1])->one();
         } else {
             if ($_POST['page'] == 'sertificate') {
                 $model = BSertificates::find()->where(['site' => 1])->one();
             } else {
                 if ($_POST['page'] == 'mainpage') {
                     $model = BMainpage::find()->where(['site' => 1])->one();
                 }
             }
         }
         $model->images = json_encode($new_array_images);
         if ($model->save()) {
             $BImages = BImages::findOne($_POST['delete_id_img']);
             if ($BImages->delete()) {
                 if (!unlink(Yii::getAlias('@webroot/' . $_POST['delete_path']))) {
                     return 'Не удалось удалить изображение локально';
                 } else {
                     return true;
                 }
             } else {
                 return 'Не удалось удалить изображение из базы';
             }
         } else {
             return 'Не удалось перезаписать изображения';
         }
     } else {
         return 'Не пришли данные для удаления';
     }
 }