protected function loadState($id) { if (($productPhoto = ProductPhoto::findOne($id)) !== null) { return $productPhoto; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getProductPhotos() { return $this->hasMany(ProductPhoto::className(), ['product_id' => 'id']); }
protected static function deletePhoto($id, $uploadedPath) { if ($photo = ProductPhoto::findOne(['id' => $id])) { if (file_exists($path = $uploadedPath . $photo->photo)) { unlink($path); $photo->delete(); return true; } } return false; }