Example #1
0
 /**
  * Creates a new ItemImg model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $itemModel = new Item();
     $imagesArray = $itemModel->getUploadImages();
     foreach ($imagesArray as $image) {
         $itemImg = new ItemImg();
         $itemImg->item_id = Yii::$app->request->post('item_id');
         $itemImg->pic = $image['pic'];
         $itemImg->title = $image['title'];
         $itemImg->position = Yii::$app->request->post('position');
         $itemImg->create_time = time();
         if (!$itemImg->save()) {
             return json_encode(['error' => Yii::t('catalog', 'save images to database fail.')]);
         }
     }
     return json_encode([]);
 }