Chapters
23 Chapters
|
2:07:02
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
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!
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!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^4.0", // v4.2.0
"doctrine/doctrine-bundle": "^2.7", // 2.10.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.4
"doctrine/orm": "^2.12", // 2.15.2
"knplabs/knp-time-bundle": "^1.18", // v1.20.0
"pagerfanta/doctrine-orm-adapter": "^4.0", // v4.1.0
"pagerfanta/twig": "^4.0", // v4.1.0
"stof/doctrine-extensions-bundle": "^1.7", // v1.7.1
"symfony/asset": "6.3.*", // v6.3.0
"symfony/asset-mapper": "6.3.*", // v6.3.0
"symfony/console": "6.3.*", // v6.3.0
"symfony/dotenv": "6.3.*", // v6.3.0
"symfony/flex": "^2", // v2.3.1
"symfony/framework-bundle": "6.3.*", // v6.3.0
"symfony/http-client": "6.3.*", // v6.3.0
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/proxy-manager-bridge": "6.3.*", // v6.3.0
"symfony/runtime": "6.3.*", // v6.3.0
"symfony/stimulus-bundle": "^2.9", // v2.9.1
"symfony/twig-bundle": "6.3.*", // v6.3.0
"symfony/ux-turbo": "^2.9", // v2.9.1
"symfony/web-link": "6.3.*", // v6.3.0
"symfony/yaml": "6.3.*", // v6.3.0
"twig/extra-bundle": "^2.12|^3.0", // v3.6.1
"twig/twig": "^2.12|^3.0" // v3.6.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.4
"symfony/debug-bundle": "6.3.*", // v6.3.0
"symfony/maker-bundle": "^1.41", // v1.49.0
"symfony/stopwatch": "6.3.*", // v6.3.0
"symfony/web-profiler-bundle": "6.3.*", // v6.3.0
"zenstruck/foundry": "^1.21" // v1.33.0
}
}
10 Comments
I've been using asset mapper while developing a small website and I encountered a problem when using it together with LiipImagineBundle to resize my images. When running in the dev environment, LiipImagineBundle can't find the images because of the additional hash that asset mapper adds to the file name.
My assets are in an
assetsdirectory in the project root.The generated path from asset mapper is
assets/img/my_image-kNM.png. But because I am running indevenv, this "aliased" file does not really exist. LiipImagine however requires the file to exists in the file system and can't find it.One way to fix this is by running
asset-map:compileso the actual files exist in thepublic/assetsdirectory. But I want to stay flexible while still developing and don't want to have to remember that I need to compile my asset map.I modified the
liip_imagine.yamlconfig and added the following lines so that Liip can find my assets and also stopped using theasset("...")twig function. I basically just let LiipImagine figure out where to load the images from.Is there an easier way to use asset mapper together with LiipImagine? It feels like right now they are fighting with each other.
Hey @Stefan-G
Sorry for my late reply. You've hit an interesting edge case. I see a few options:
1) Do what you did, but add that config only for the
devenvironment2) Run
symfony console asset-map:compile --watchand keep it running3) A more robust solution: create your own loader service. You could "decorate" the main service
Liip\ImagineBundle\Binary\Loader\LoaderInterfaceand remove the hash part from the filename before processing it.Cheers!
There is a problem with asset mapper in production enviroment with uploaded files since it requires the compile option to be run.
For example, if your app allows users to upload images, but they are private images, so you store them in assets, and then it works great when in dev, but in prod it doesnt work because compile is not being run after every image upload.
That makes asset mapper incompatible with uploaded images from vich uploader bundle, etc?
Hey @MarkR
Sorry for our super late reply. Somehow we never saw this question
The files/images you store inside your private assets directory are meant for static files of your application, not files uploaded by users. The uploads should be stored in a public directory (you can add authorization rules so only file owners can actually access them)
I hope it helps. Cheers!
How can I include an image (e.g., an icon like assets/images/icon.png) in Symfony AssetMapper without applying versioning to it?
Hey @ahmedbhs ,
Hm, I wonder what's the reason behind avoiding using hash for that icon? Hash is always a good idea, no downsides at all and it makes your deploys more robust.
But if you really need that - I think you just should stop handling that image via AssetMapper then. Just put that image somewhere in the public/ dir and reference it with
{{ asset() }}. IIRC it should build the correct path w/o the hash. Because you can't use versioning for some assets only, it's a global strategy, you either use it in AssetMapper or not at all.I hope that helps!
Cheers!
no more build system? :D mind is blown!
When running debug:asset it explodes!
It is likely to do with me experimenting with Symfony 7.
I can't find any info on it and am not sure right now if this is a showstopper.
I wonder if this rings any bell and if you have any super magic counterspell to this error.
Tnx!
Hey @Sjoerd-N!
Upgrade
symfony/asset-mapperto the absolute latest version. A bug was introduced in 7.0.4 and should be fixed in 7.0.5.Cheers!
Hi, nice to find that symfony goes back, abandoning once and for all the prebuilt js in favor of assets, among other things that of assets is a very old (not bad) concept used by an excellent framework (I won't name names) considered minor compared to symfony. Does this method promise to become the best way to deal with css and js or is it just an alternative? Thanks
Hey @pasquale_pellicani!
I'm pretty happy too - it's really nice to work with :)
I can't say for sure. My best guess right now is that we, for the next few years, will have 2 paths. The "build" systems are now so widely used, that I think it will take time for people to realize that they don't need it. And, build systems WILL still exist forever, at the very least, to handle things like JSX, Vue, etc. The challenge over the next 12 months will be to (A) continue improving the DX for asset mapper (we have some work to do on 6.4 for this, especially related to making CSS nicer to use I think) and (B) reminding people this exists and it's excellent! It also helps that we're leveraging "web standards" (e.g. importmaps, ECMAScript code).
Anyway, we'll see. But there is nothing preventing this method from becoming the main way of handling things for non-SPA sites.
Cheers!
"Houston: no signs of life"
Start the conversation!