prod.log
请求。CRITICAL:未捕获的PHP异常Symfony\Component\Form\Exception\TransformationFailedException:">无法转换属性路径"location"的值:应为数字。"在/home/placeme1/vendor/Symfony/symfoy/src/Symfony/Component/Form.PHP行1107
{"exception":"[object](Symfony\Component\Form\exception\TransformationFailedException(代码:0(:无法转换属性路径\"location\"的值:应为数字。位于/home/placeme1/vendor/Symfony/Symfony/src/Symfony/Component/Form.Form.php:1107,Symfony\Component\Form\Exception\TransformationFailedException(代码:0(:应为数字。at/home/placeme1/vendor/symfony/symfoy/src/symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php:113("}[]
控制器操作
/**
* @Route("/student/details/edit")
*/
public function editStudentAction(Request $request)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$student = $em->getRepository('AppBundle:Student')
->findOneBy(['userId'=>$user->getId()]);
$categoryQuery = $em->getRepository('AppBundle:SkillCategory')->findAll();
$form = $this->createFormBuilder($student)
->add('university',TextType::class)
->add("course",TextType::class)
->add("location",IntegerType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
if($form->isValid()) {
$review_data = $form->getData();
$em->persist($review_data);
$em->flush();
$this->addFlash('success', 'Your Review has been added');
return $this->redirect('/profile');
} else {
return new Response("form is not valid");
}
} else {
//return new Response("not correct");
}
return $this->render('student/editStudent.html.twig',array(
"editStudentForm" => $form->createView(),
"skillCategorys" => $categoryQuery,
));
}
您能给我们发送学生实体声明(class、yml或xml(吗?
学生位置字段似乎不是整数类型。
如果你像这样删除位置字段上的表单类型,它会起作用吗?
$form = $this->createFormBuilder($student)
->add('university',TextType::class)
->add("course",TextType::class)
->add("location")
->getForm();