Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id_category)
 {
     $model = new CatalogProduct();
     $model->id_category = $id_category;
     $this->breadcrumbs = CatalogCategory::getParents($model->id_category, true);
     $this->breadcrumbs[] = 'Добавление товара';
     // Дополнительные фото
     $productImages = new CatalogImage();
     $criteria = new CDbCriteria();
     $criteria->compare('id_product', -1);
     $photoDataProvider = new CActiveDataProvider('CatalogImage', array('criteria' => $criteria, 'pagination' => false));
     $folder = 'images/catalog';
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['CatalogProduct'])) {
         $model->attributes = $_POST['CatalogProduct'];
         // Чтобы красиво написано было
         //$model->noyml=!$model->noyml;
         $model->hide = !$model->hide;
         if ($model->save()) {
             // записываем атрибуты товара, переданные из формы
             if (isset($_POST['CatalogProductAttribute'])) {
                 $model->productAttributeSave($_POST['CatalogProductAttribute']);
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'productImages' => $productImages, 'photoDataProvider' => $photoDataProvider));
 }
Пример #2
0
 public function actionIndex()
 {
     $this->metaInfoGenerate('Предложить животное', 'Предложить животное', 'Предложить животное');
     $model = new ResponseForm();
     if (isset($_POST['ResponseForm'])) {
         $model->attributes = $_POST['ResponseForm'];
         if ($model->validate()) {
             $product = new CatalogProduct('response');
             $product->attributes = $model->getProductAttributes();
             if ($product->save()) {
                 $admin = User::model()->findByPk(1);
                 $body = $this->renderPartial('template', array_merge(array('product' => $product)), true);
                 if (Yii::app()->getModule('callback')->sendMessage($admin->email, 'Предложение животного с сайта ' . Yii::app()->config->sitename, $body)) {
                     Yii::app()->user->setFlash('callback_message', 'Ваше предложение успешно отправлено администратору сайта.');
                 } else {
                     Yii::app()->user->setFlash('callback_message', 'В данный момент отправка предложения невозможна.');
                 }
             }
         }
     }
     $this->render('index', array('model' => $model));
 }