/** * Creates a new Photo model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Photo(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('photoCreate', ['model' => $model]); } }
/** * 保存创建和修改的信息 */ public function actionSave() { try { $post = Yii::$app->request->post(); $id = isset($post['photo_id']) ? $post['photo_id'] : ''; if (!empty($post['photoAlbum_id'])) { $post['Photo']['album_id'] = $post['photoAlbum_id']; } if (!empty($id)) { $model = $this->findModel($id); if ($model->load($post) && $model->save()) { $photo_id = $id; } } else { $model = new Photo(); if ($model->load($post) && $model->save()) { $photo_id = Yii::$app->db->getLastInsertID(); } } if (empty($photo_id)) { throw new \Exception('写入照片失败'); } } catch (\Exception $exp) { $result = ['statusCode' => '300', 'message' => $exp->getMessage(), 'navTabId' => 'photo_photo_index_id', 'forwardUrl' => '', 'callbackType' => '']; echo Json::encode($result); exit; } $result = ['statusCode' => '200', 'message' => '操作成功', 'navTabId' => 'photo_photo_index_id', 'forwardUrl' => '', 'callbackType' => 'closeCurrent']; echo Json::encode($result); exit; }