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!
27.
Rendering the File List Client Side
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
}
}
15 Comments
Instead of references my list is images. How would I be able to output this:
`<a href="{{ uploaded_asset(image.imagePath) }}">
</a>
`in the:
render() {
Hey Steve D.
Sorry but I just don't understand your problem. Could you elaborate it a bit more? What error are you experiencing? What have you debugged already? What's your final goal?
Cheers!
All sorted Diego. Your help on my other issue regarding the private files lead me straight to the answer to this one. I juts need the actual url to the "download" end point . and not the twig code for it.
Thank you again
Steve
Hi!
I used this tutorial to create a small upload system.
Right now, in the render method in the JS file, we have:
The result is a list of uploads, with:
My upload system only concerns images. So I'd like to be able to display a thumbnail of the uploaded image.
But I'm having trouble.
In twig files, I can do this to display the image:
Which will call :
But in JS? I did try the full path, /public/uploads/post_reference/reference_filename but it did not work.
Any idea or help ?
Thanks for the hard work !
Hey @Christina-V
Do you see an error in your Browser console? Double-check that the file exists and it is publicly accessible, in other words, check file permissions
Cheers!
Hey @MolloKhan,
Nice of you to answer, I appreciate.
So in my app.js file,
render()method, I got this:And indeed, it will display this error (browser console):
Indeed, it's not going in the public folde and so it's not the right path.
I guess because I don't use the
asset()function, but I can't since I'm in the JS file, and not the twig.About the file permissions, if I have a look in the folder while I'm IN my PHP container (I use docker) I got this:
Is it good ? Anf if no, how can I change this, in the process of the upload ?
Thanks!
Ok, I see you have a different URL in JavaScript than in your Twig template. If you're using Stimulus, you can pass data from Twig to JS using Stimulus values https://stimulus.hotwired.dev/reference/values
If you're not, you could generate the path in Twig and set it to a
data-urlattribute in your HTML element, then you just use it in your JS fileBy the way, the file permissions look good to me
Cheers!
thank you @tisserand for this beautiful javascript code, I know you inspired it from React, but it's still beautiful.
Hi, is posbile with dropzone o fileType of symfony . read the content the file then save each one in a entity Post ?, the client need insert 600 post at day from the file, how can make this? plus this filetype live othes field like texttype and datetime, like form with children
Hi @sansxd!
Hmm. So, once a file is uploaded (via Dropzone or the FileType), you ultimately end up with an UploadedFile object. Usually you then move the file to some final location, like we've done. That object has a method called
->getContent(). So, instead of moving the file, you could call that, get the contents, then set that onto a newPostentity :).Let me know if that helps!
You're introducing an XSS vulnerability here. Unless Symfony does anything special to the original file name, it'll be whatever the user chooses, even if that includes special characters like < or " that are needed to introduce onwhatever="" attributes or script tags to the page.
Hey there,
Thanks for pointing it out. For XSS attacks you can use Symfony's CSRF protection on your forms. In this case, you'd have to rename the file before saving it on your server
Cheers!
After adding the class ReferenceList and putting the var Referencelist inside the document.ready function, I got this error in the console:
ReferenceError: ReferenceList is not defined admin_article_form.js:3:9After putting it outside the document.ready, after the class, it worked, am I the only one? A wrong scope?
EDIT: no luck, later on same thing happens when trying to pass back the updated references.
EDIT: My fault, I had put the function initializeDropzone within the document.ready
EDIT: After putting everything in the right place, there is no feedback in the client side list when a new file was uploaded, in the console: "
TypeError: referenceList.addReferenceis not a function"What could be wrong?
Hey Cavisv,
I'm glad you was able to fix your previous issues, well done!
About the "TypeError: referenceList.addReference is not a function" - hm, you probably need to debug it more, you can call "console.log(referenceList);" right before "referenceList.addReference()" call. Does it referenceList object? Probably you're passing the wrong object to the initializeDropzone() function.
Cheers!
thanks for the feedback, it was just a missing function :d
`addReference(reference) {
this.references.push(reference);
now it works
"Houston: no signs of life"
Start the conversation!