コード例 #1
0
 /**
  * @param $id
  * @throws CHttpException
  */
 public function actionAddOption($id)
 {
     if (Yii::app()->getRequest()->getIsPostRequest()) {
         $model = $this->loadModel($id);
         $option = new AttributeOption();
         $option->setAttributes(['value' => Yii::app()->getRequest()->getPost('value'), 'attribute_id' => $model->id]);
         if (true === $option->save()) {
             Yii::app()->ajax->success();
         }
         Yii::app()->ajax->failure();
     } else {
         throw new CHttpException(400, Yii::t('StoreModule.store', 'Bad request. Please don\'t use similar requests anymore'));
     }
 }
コード例 #2
0
ファイル: Attribute.php プロジェクト: syrexby/domovoishop.by
 /**
  * @param array $attributes
  * @return bool
  * @throws CDbException
  */
 public function setMultipleValuesAttributes(array $attributes)
 {
     if (!$this->isMultipleValues()) {
         return true;
     }
     $transaction = Yii::app()->getDb()->beginTransaction();
     try {
         foreach ($attributes as $attribute) {
             $model = new AttributeOption();
             $model->setAttributes(['attribute_id' => $this->id, 'value' => trim($attribute)]);
             if (false === $model->save()) {
                 throw new CDbException();
             }
         }
         $transaction->commit();
         return true;
     } catch (Exception $e) {
         $transaction->rollback();
         return false;
     }
 }