public function reorderGalleryImages($idsSorted) { if (count($idsSorted) > 1) { foreach ($idsSorted as $newPosition => $id) { $galleryImage = GalleryImage::findOne($id); $galleryImage->sort_order = $newPosition; $galleryImage->save(); } } }
public function actionDeleteImage($id) { if (Yii::$app->request->isAjax) { try { $galleryImage = GalleryImage::findOne($id); $galleryImage->delete(); $message = Yii::t('app', 'Image deleted Successfully'); } catch (\Exception $e) { $message = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage(); } return $message; } }
/** * @return \yii\db\ActiveQuery */ public function getGalleryImages() { return $this->hasMany(\common\models\GalleryImage::className(), ['gallery_id' => 'id']); }