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