Symfony\Component\HttpFoundation\Request::getUriForPath PHP Method

getUriForPath() public method

Generates a normalized URI for the given path.
public getUriForPath ( string $path ) : string
$path string A path to use instead of the current one
return string The normalized URI for the path
    public function getUriForPath($path)
    {
        return $this->getSchemeAndHttpHost().$this->getBaseUrl().$path;
    }

Usage Example

Example #1
0
 /**
  * @Route("uploadFile", name="pic.upload.file")
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function uploadFilesAction(Request $request)
 {
     $this->get("logger")->debug("Entramos al subidor de imágenes");
     $em = $this->getDoctrine()->getManager();
     $files = $request->files;
     $this->get("logger")->debug("Despues de sacar las imagenes del request");
     $this->get("logger")->debug(sprintf("Conteo de los archivos a subir: %s", count($files)));
     $data = array();
     if (count($files) > 0) {
         foreach ($files as $file) {
             $md5 = md5_file($file);
             $result = $em->createQuery("select p from PicboardBundle:ThePicture p where p.md5 = :md5 " . " and p.deletedAt = null")->setParameter("md5", $md5)->getOneOrNullResult();
             if (is_null($result)) {
                 $ext = strtolower($file->getClientOriginalExtension());
                 $fileName = $md5 . "." . $ext;
                 $file->move('pictures/', $fileName);
                 $this->get("logger")->debug(sprintf("El nombre del archivo es: %s", $fileName));
                 $picture = new ThePicture();
                 $picture->setMd5($md5);
                 $picture->setPath($fileName);
                 $em->persist($picture);
                 $em->flush();
                 $url = $request->getUriForPath("/pictures/" . $picture->getPath());
                 $content = array('url' => $url);
                 array_push($data, $content);
             } else {
                 $url = $request->getUriForPath("/pictures/" . $result->getPath());
                 $content = array('url' => $url);
                 array_push($data, $content);
             }
         }
         return new JsonResponse($data);
     }
     throw new InvalidArgumentException("No se pueden subir imagenes si no existen");
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::getUriForPath