/** * Get the validation errors * * @param ConstraintViolationList $errors Validator error list * * @return FOSView */ protected function getValidationErrorsView($errors) { $msgs = array(); $it = $errors->getIterator(); foreach ($it as $val) { $msg = $val->getMessage(); $params = $val->getMessageParameters(); //using FOSUserBundle translator domain 'validators' $msgs[$val->getPropertyPath()][] = $this->get('translator')->trans($msg, $params, 'validators'); } $data = array("status" => "error", "status_code" => 400, "status_text" => "Bad Request", "current_content" => "", "message" => $msgs); $view = FOSView::create($data); $view->setStatusCode(400); return $view; }
/** * Get the validation errors. * * @param ConstraintViolationList $errors Validator error list * * @return View */ protected function getErrorsView(ConstraintViolationList $errors) { $msgs = array(); $errorIterator = $errors->getIterator(); foreach ($errorIterator as $validationError) { $msg = $validationError->getMessage(); $params = $validationError->getMessageParameters(); $msgs[$validationError->getPropertyPath()][] = $this->get('translator')->trans($msg, $params, 'validators'); } $view = View::create($msgs); $view->setStatusCode(400); return $view; }
/** * Get the validation errors * * @param ConstraintViolationList $errors Validator error list * * @return FOSView */ private function get_errors_view($errors) { $msgs = array(); $it = $errors->getIterator(); //$val = new \Symfony\Component\Validator\ConstraintViolation(); foreach ($it as $val) { $msg = $val->getMessage(); $params = $val->getMessageParameters(); //using FOSUserBundle translator domain 'validators' $msgs[$val->getPropertyPath()][] = $this->get('translator')->trans($msg, $params, 'validators'); } $view = FOSView::create($msgs); $view->setStatusCode(400); return $view; }