예제 #1
0
 /**
  * Updates an existing Album model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $data = Yii::$app->request->post();
     $ret = $model->load($data);
     $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
     if ($ret && $model->upload() && $model->save()) {
         CategoryRelationship::deleteAll(['media' => $id]);
         if (isset($data['Album']['categoryID'])) {
             foreach ($data['Album']['categoryID'] as $val) {
                 $relation = new CategoryRelationship();
                 $relation->media = $id;
                 $relation->category = $val;
                 $relation->type = 0;
                 $relation->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->ID]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
예제 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategoryRelationship()
 {
     return $this->hasMany(CategoryRelationship::className(), ['category' => 'ID']);
 }