
Validators in Symfony
http://symfony.com/doc/3.2/components/validator/resources.html
Example of usage of @Assert\File
/**
* @var \SplFileInfo
*
* @Assert\File(
* mimeTypes = {"application/x-bittorrent"},
* mimeTypesMessage = "Your file was not recognize as a .torrent file.",
* maxSize = "100k",
* maxSizeMessage = "Your .torrent file was rejected because it is too large.",
* disallowEmptyMessage = "The uploaded torrent file seems completely empty.",
* uploadIniSizeErrorMessage = "Your torrent file was rejected because it is too big (limited by server). {{ limit }}{{ suffix }} max allowed.",
* groups={"default", "torrent_menu"}
* )
*/
protected $uploadedFileByUrl = null;
and official docs: https://symfony.com/doc/3.2/reference/constraints/File.html#maxsize
validation groups example:
https://symfony.com/doc/3.2/form/data_based_validation.html
When one want a different validation for the same form (different for when the "Product" is first created, and different when it is edited, but we're using here the same form)
"Suppose now, that you don’t want the user to be able to change the name value once the object has been created. To do this, you can rely on Symfony’s Event Dispatcher system to analyze the data on the object and modify the form based on the Product object’s data. In this entry, you’ll learn how to add this level of flexibility to your forms."
http://symfony2-document.readthedocs.io/en/latest/cookbook/form/dynamic_form_generation.html
Leave Validators in Symfony to:
Read more #forms posts
Best Posts From symfonydev
We have not curated any of symfonydev's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From symfonydev
- {@InheritDoc} plugin for PhpStorm
- How to implement a rollback feature
- Bug in behat 3.4.0 - No specifications found at path(s), This might be because of incorrect paths configuration in your `suites`.
- MultiUpload of files in Symfony 3.2
- Executing command line script for different environment (database)
- Validators in Symfony
- String encoding in php
- Command bus in Symfony
- Providing explicit UID (if the user is the same on client and host) at docker run will help with file permissions
- Check if there are the same values for given column