From 324ad7253b67ce0e10c9c450cf32e72e7190d6b5 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Sat, 15 Sep 2018 18:44:14 +0200 Subject: [PATCH] Added docs for different protocols as asset base_url --- components/asset.rst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/components/asset.rst b/components/asset.rst index c6a8c6b0d33..6a4dd24fb70 100644 --- a/components/asset.rst +++ b/components/asset.rst @@ -372,6 +372,35 @@ document inside a template:: echo $packages->getUrl('resume.pdf', 'doc'); // result: /somewhere/deep/for/documents/resume.pdf?v1 +Local files and other protocols +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In cases of e.g. generating a pdf from html you want directly link to the local file for performance reason you can use the asset component the following way: + + use Symfony\Component\Asset\UrlPackage; + // ... + + $localPackage = new UrlPackage( + 'file:///path/to/images/', + new EmptyVersionStrategy() + ); + + echo $localPackage->getUrl('/logo.png'); + // result: file:///path/to/images/logo.png + +Or link to a file on a ftp server: + + use Symfony\Component\Asset\UrlPackage; + // ... + + $ftpPackage = new UrlPackage( + 'ftp://example.com/images/', + new EmptyVersionStrategy() + ); + + echo $ftpPackage->getUrl('/logo.png'); + // result: ftp://example.com/images/logo.png + Learn more ----------