Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove old File Upload article + improve the new one#6040

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
wouterj wants to merge10 commits intosymfony:2.3fromwouterj:issue_5375

Conversation

wouterj
Copy link
Member

QA
Doc fix?yes
New docs?yes
Applies to2.3+
Fixed tickets#5375

The old file upload article wasn't good, a new one was written by@javiereguiluz but the old one remained online. This PR removes the old one and documents the missing bits in the new article.

@wouterj
Copy link
MemberAuthor

Btw, why do we use an Entity property to store both the uploaded file and file path? Wouldn't it be better to use an unmapped field?


If you are using Doctrine to store the Product entity, you can create a
:doc:`Doctrine listener </cookbook/doctrine/event_listeners_subscribers>` to
automatically upload the file when persisting the entity::
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I wondering if we should show code + config, or just link to the other article and just mentioning this as a little tip.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I like how you've handled it here: with code+config (it's really not too long).

@Raistlfiren
Copy link
Contributor

@wouterj, if I might make an addition as well.... It might be good to include how to handle files when editing them. For example, if I have a simple form like you included in the example, then I would need to either set data_class to null on the brochure field or convert the string to a File object. Otherwise, the form will error out and say - "The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) string". Maybe creating the file object is better in a data transformer, not sure. Thoughts?

@xabbuh
Copy link
Member

Btw, why do we use an Entity property to store both the uploaded file and file path? Wouldn't it be better to use an unmapped field?

I think this was done to always trigger the lifecycle callback methods. If only the file path were mapped to the database, lifecycle callbacks would never be triggered if only the uploaded file was changed (Doctrine would not treat the entity as changed at all).

However, I tend to say that we should rather move the whole file uploding logic into a DTO and not pollute the entity with logic that doesn't belong there.

# app/config/parameters.yml
parameters:
# ...
brochures_directory: '%kernel.root_dir%/../web/uploads/brochures'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This makes more sense inconfig.yml - it's not a value that would normally need to be changed on a machine-by-machine basis, and devs wouldn't/shouldn't need to worry about configuring it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

And actually, we're dependent on it later when we make the paths to it in the Twig template.

@weaverryan
Copy link
Member

@wouterj I added 2 small comments, but 👍 from me after that. Sorry for the long delay - I'm also excited to remove the old, terrible article.

@Koc
Copy link
Contributor

Koc commentedApr 7, 2016

@wouterj please add info about uploading and validating multiple files, see#5603 request

@Koc
Copy link
Contributor

Koc commentedApr 7, 2016

@weaverryan can we create redirect from old url to the new article?

@xabbuh
Copy link
Member

@Koc That's done with the entry in theredirection_map file.

@wouterj
Copy link
MemberAuthor

I've updated the article. Should be ready to merge now

}
}

This class can be registered as a service in the service container:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This class can be registered as a service in the service container:

->

Then, define a service for this class: ?

@wouterj
Copy link
MemberAuthor

While testing this code in an application I found a few bugs which I fixed inf6068c9. Also, I strumbled onto issues creating an edit form as it needs aFile instance. To avoid problems for readers, I've added two little tip boxes in0c54b8a.

It's now even more ready to merge than it was this afternoon :)

@javiereguiluz
Copy link
Member

@wouterj amazing! Thanks for testing everything thoroughly in a real project 🙇


You can now use the following code to link to the PDF brochure of an product:
You can use the following code to link to the PDF brochure of an product:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

a product

@xabbuh
Copy link
Member

👍 I like the changes you made here.

However, for the future I think we can improve things even more by introducing a DTO that would be used to build the form and doing the file upload. That way we would not need to have the hacks being present currently.

@weaverryan
Copy link
Member

I left a minor comment, but let's merge this :) 👍

@wouterj
Copy link
MemberAuthor

Updated again.@xabbuh using a DTO is exactly what I thought when improving this article.

@weaverryan I can't find your minor comment.

@javiereguiluz
Copy link
Member

@wouterj you say "updated again" but I can't see any new commits 😕

@wouterj
Copy link
MemberAuthor

@javiereguiluz as it was a very small typo fix, I merged it into the previous commit:94e21ff#diff-bcae3aaf74848d919ee531cad0d95547R192

@xabbuh
Copy link
Member

Thank you Wouter.

xabbuh added a commit that referenced this pull requestMay 29, 2016
…outerJ)This PR was squashed before being merged into the 2.3 branch (closes#6040).Discussion----------Remove old File Upload article + improve the new one| Q | A| --- | ---| Doc fix? | yes| New docs? | yes| Applies to | 2.3+| Fixed tickets |#5375The old file upload article wasn't good, a new one was written by@javiereguiluz but the old one remained online. This PR removes the old one and documents the missing bits in the new article.Commits-------888c61c Remove old File Upload article + improve the new one
@xabbuhxabbuh closed thisMay 29, 2016
@wouterjwouterj deleted the issue_5375 branchMay 29, 2016 09:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@wouterj@Raistlfiren@xabbuh@weaverryan@Koc@javiereguiluz

[8]ページ先頭

©2009-2025 Movatter.jp