Skip to content

Commit 7883901

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: Added a tip about atPath() method Added the missing class imports Update upload_file.rst for handling FileException
2 parents dba62b4 + 33f40e0 commit 7883901

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

controller/upload_file.rst

+16-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Finally, you need to update the code of the controller that handles the form::
100100
namespace AppBundle\Controller;
101101

102102
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
103+
use Symfony\Component\HttpFoundation\File\Exception\FileException;
103104
use Symfony\Component\HttpFoundation\Request;
104105
use Symfony\Component\Routing\Annotation\Route;
105106
use AppBundle\Entity\Product;
@@ -123,11 +124,15 @@ Finally, you need to update the code of the controller that handles the form::
123124

124125
$fileName = $this->generateUniqueFileName().'.'.$file->guessExtension();
125126

126-
// moves the file to the directory where brochures are stored
127-
$file->move(
128-
$this->getParameter('brochures_directory'),
129-
$fileName
130-
);
127+
// Move the file to the directory where brochures are stored
128+
try {
129+
$file->move(
130+
$this->getParameter('brochures_directory'),
131+
$fileName
132+
);
133+
} catch (FileException $e) {
134+
// ... handle exception if something happens during file upload
135+
}
131136

132137
// updates the 'brochure' property to store the PDF file name
133138
// instead of its contents
@@ -214,6 +219,7 @@ logic to a separate service::
214219
// src/AppBundle/Service/FileUploader.php
215220
namespace AppBundle\Service;
216221

222+
use Symfony\Component\HttpFoundation\File\Exception\FileException;
217223
use Symfony\Component\HttpFoundation\File\UploadedFile;
218224

219225
class FileUploader
@@ -229,7 +235,11 @@ logic to a separate service::
229235
{
230236
$fileName = md5(uniqid()).'.'.$file->guessExtension();
231237

232-
$file->move($this->getTargetDirectory(), $fileName);
238+
try {
239+
$file->move($this->getTargetDir(), $fileName);
240+
} catch (FileException $e) {
241+
// ... handle exception if something happens during file upload
242+
}
233243

234244
return $fileName;
235245
}

reference/forms/types/options/property_path.rst.inc

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ property_path
33

44
**type**: ``any`` **default**: ``the field's name``
55

6-
Fields display a property value of the form's domain object by default.
7-
When the form is submitted, the submitted value is written back into the
8-
object.
9-
10-
If you want to override the property that a field reads from and writes
11-
to, you can set the ``property_path`` option. Its default value is the field's
12-
name.
6+
By default form fields read from and write to the properties with the same names
7+
in the form's domain object. The ``property_path`` option lets you define which
8+
property a field reads from and writes to. The value of this option can be any
9+
:doc:`valid PropertyAccess syntax </components/property_access>`.
1310

1411
If you wish the field to be ignored when reading or writing to the object
1512
you can set the ``property_path`` option to ``false``, but using

validation/custom_constraint.rst

+6
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ With this, the validator ``validate()`` method gets an object as its first argum
196196
}
197197
}
198198

199+
.. tip::
200+
201+
The ``atPath()`` method defines the property which the validation error is
202+
associated to. Use any :doc:`valid PropertyAccess syntax </components/property_access>`
203+
to define that property.
204+
199205
Note that a class constraint validator is applied to the class itself, and
200206
not to the property:
201207

0 commit comments

Comments
 (0)