Chapters
40 Chapters
|
4:39:58
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
18.
Absolute Asset Paths
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial is built on Symfony 4 but works great in Symfony 5!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"aws/aws-sdk-php": "^3.87", // 3.87.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.1
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.1
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.9.0
"league/flysystem-aws-s3-v3": "^1.0", // 1.0.22
"league/flysystem-cached-adapter": "^1.0", // 1.0.9
"liip/imagine-bundle": "^2.1", // 2.1.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.1.0
"oneup/flysystem-bundle": "^3.0", // 3.0.3
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.2.3
"symfony/console": "^4.0", // v4.2.3
"symfony/flex": "^1.9", // v1.21.6
"symfony/form": "^4.0", // v4.2.3
"symfony/framework-bundle": "^4.0", // v4.2.3
"symfony/property-access": "4.2.*", // v4.2.3
"symfony/property-info": "4.2.*", // v4.2.3
"symfony/security-bundle": "^4.0", // v4.2.3
"symfony/serializer": "4.2.*", // v4.2.3
"symfony/twig-bundle": "^4.0", // v4.2.3
"symfony/validator": "^4.0", // v4.2.3
"symfony/web-server-bundle": "^4.0", // v4.2.3
"symfony/yaml": "^4.0", // v4.2.3
"twig/extensions": "^1.5" // v1.5.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.1.0
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.2.3
"symfony/dotenv": "^4.0", // v4.2.3
"symfony/maker-bundle": "^1.0", // v1.11.3
"symfony/monolog-bundle": "^3.0", // v3.3.1
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.2.3
"symfony/stopwatch": "4.2.*", // v4.2.3
"symfony/var-dumper": "^3.3|^4.0", // v4.2.3
"symfony/web-profiler-bundle": "4.2.*" // v4.2.3
}
}
12 Comments
This doesn't turn out true in production to me, where getBasePath gives me exactly the same string i put in the SITE_BASE_URL; am I missing something?
Hey Matteo Maranta
I think that's the right behavior (unless I misunderstood something), you're seeing your env var
SITE_BASE_URLbecause it's being used in thegetBasePath()methodCheers!
Please provide a link to the preferred wkhtmltopdf package/bundle for symfony, as long as you mention it (which is a 100% great way to learn about new tools).
And, what exactly is the other approaches Ryan mentions at 4:34? I'd like to be able to make an informed decision/choice on this matter.
Hey Voltel,
Our advice is KnpSnappyBundle: https://github.com/KnpLabs/... - that just a wrapper around Wkhtmltopdf tool. And looks like it' the most popular bundle for Symfony that works with PDF.
Unfortunately, I'm not sure what Ryan had on mind at that second, but I'd say that env vars approach is probably the best option. Another option would be to hardcode URLs, but that's not a good option.
Cheers!
Hi victor!
About the other approach around 4:34, I don't remember exactly (to be honest), but I believe that it mostly involved different approaches to using the SITE_BASE_URL. In Symfony, there is an idea of "asset packages" and you can define a base URL for each "asset package". Then, when you use the
asset()function (or use that same code in PHP), that package will automatically add the base URL. I think this was the other approach I played with. In the end, I didn't choose that because it's... just a bit more confusing to explain. The approach I used is pretty direct: we create aSITE_BASE_URLvariable and then use it in our code. We're not leveraging any, sort of, "invisible magic" to get the job done.Cheers!
Hi team !
I'm little confused between when to use % and @ to autowire services in services.yaml ?
Could you please put some light on it ! Thanks a lot !
Hey Raed
The
@character is used to indicate Symfony that you want to inject a serviceThe
%sign indicates Symfony that you want to inject a parameter or environment variable through using the%env(SOME_VARIABLE)%notationDoes it makes more sense to you now?
Cheers!
Hey MolloKhan,
Thank you so much for this very helpful and clear clarification.
Personally I would like to avoid hardcoding that value and, instead, use `{{ app.request.schemeAndHttpHost }}` to fix that or create my own Twig filter/function. On my own website, radiolista.pl, which is open source, I even use <base> tag: https://github.com/TomaszGa... I don't know whether wkhtmltopdf and email clients support <base>, although.
Hey Tomasz,
What exactly hardcoded value are you talking about? If you're about SITE_BASE_URL - it's not exactly hardcoded value, it's dynamic variable.
Cheers!
I mean for me it seems to be better to rely on Symfony magic and mechanism already implemented in Request class instead "hardcoding" it into environment variable which you have to always fill in before starting real work. It's personal, although. :)
Hey Tomasz,
Ah, yes, I see what you mean :) Personally, I agree with you and I'm always trying to achieve it with app.request things :) But! Sometimes we need to have that HTTP host somewhere in the config, like in our case here where we set it uploads_base_url parameter, i.e. sometimes we need to have that parameter hardcoded. Or for host specific routes, etc. Yes, it causes some incoveniences that you have to tweak that parameter on some servers to get project working, but still it's done in one spot only, you don't have to change all possible hardcoded URLs all over the project code as we use that env var values everywhere, so just need to tweak that env var.
I hope this makes sense for you! But I agree, if you can avoid using such env var in favor of using app.request in your project - that would be even better.
Cheers!
"Houston: no signs of life"
Start the conversation!