Skip to content

Added docs for different protocols as asset base_url #10347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions components/asset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------

Expand Down