コード例 #1
0
 public function actionLike($gid)
 {
     if ($id = intval(preg_replace('/\\D/', '', Yii::$app->request->post('id')))) {
         if ($image = Gallery::findOne($gid)->getBehavior('galleryBehavior')->getImage($id)) {
             /* @var GalleryImage $image */
             $result = 0;
             $liked = Yii::$app->request->cookies->getValue('liked', []);
             if (Yii::$app->request->post('liked') !== 'true') {
                 if ($image->liked > 0 && ($result = $image->LikedDown()) && ($key = array_search($id, $liked)) !== false) {
                     unset($liked[$key]);
                 }
             } else {
                 if (($result = $image->LikedUp()) && !in_array($id, $liked)) {
                     $liked[] = $id;
                     sort($liked);
                 }
             }
             if ($result) {
                 Yii::$app->response->cookies->add(new \yii\web\Cookie(['name' => 'liked', 'value' => $liked]));
             }
         }
     }
 }
コード例 #2
0
 /**
  * Finds the Gallery model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Gallery the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Gallery::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #3
0
 public function actionDeleteGalleryImage()
 {
     $id = (int) $_POST['id'];
     $model = Gallery::findOne($id);
     if ($model != null) {
         FileUploader::delete($model->image, "product");
         $model->delete();
     }
 }