コード例 #1
0
 public function actionDelete()
 {
     if (!isset($_POST['imageId'])) {
         App::instance()->show404();
         exit;
     }
     /** @var \models\Image $model */
     $model = Image::findByID((int) $_POST['imageId']);
     if (!$model || $model->uid != App::instance()->getUser()->getId()) {
         App::instance()->show404();
         exit;
     }
     if ($model->delete()) {
         $response['error'] = false;
     } else {
         $response = json_encode(['error' => true]);
     }
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH']) {
         $response['totalCount'] = Image::countByProp('uid', App::instance()->getUser()->getId());
         echo json_encode($response);
     } else {
         $this->redirect('/site/index/');
         echo $response;
     }
 }