Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Error for file validation then using symfony validator as standalone class in my php project

$
0
0

I work on a php project and implement symfony validation as a standalone class. Everything is ok, but then I try to validate file I have an error and I don't know how to solve it. Can somebody help me?

in my functions I have

    function processFile(){    global $request;    $file = $request->files->get('file');    $validateFile = ['file' => new Assert\File(['maxSize' => '64M','maxSizeMessage' => 'The file is too big','mimeTypes' => ['pdf' => 'application/pdf'],'mimeTypesMessage' => 'The format is incorrect, only PDF allowed','uploadNoFileErrorMessage' => 'No file was selected'    ]),];     $validator = Validation::createValidator();    $violations = $validator->validate($arrayData, $validateFile);    if (0 !== count($violations)) {        $errorMessages = getErrorMessage($violations);       require_once(TEMPLATES . 'processFileForm.php');       die();        } /**     * @param $violations     * @return array     */    function getErrorMessage($violations): array    {        $accessor = PropertyAccess::createPropertyAccessor();        $errorMessages = array();        foreach ($violations as $violation) {            $accessor->setValue($errorMessages, ($violation->getPropertyPath()), $violation->getMessage());        }        return $errorMessages;    }

if I dump the violations I see the error message for not correct format and so on for file validation, but it give me an error on

Fatal error: Uncaught Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException: The property path should not be empty.


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>