我有这个没有日期功能的代码。它将数据更新为MySQL。
但是我一直在使用DateTime字段收到错误:
FatalThrowableError in DateTimeType.php line 53:
Call to a member function format() on array
将其设置为DateTime字段。
public function EditData($id, Request $request){
$path ='AppBundle:eqData';
$rep = $this->getDoctrine()->getRepository($path);
$data = $rep->getData($id);
if ($request->isMethod('POST')){
$em = $this->getDoctrine()->getManager();
$event = $em->getRepository('AppBundle:eqEvent')->find($id);
$request = $request->request->all();
$date = $request['form']['Date'];
$edit->setDate($date);
$em->flush();
}
$edit->setEventDate($data[0]->getEventDate());
$form = $this->CreateFormBuilder($event)
->add('EventDate', DateTimetype::class)
->add('Save', SubmitType::class, array('label' => 'Save'))
->getForm();
return $this->render('edit.html.twig', array(
'form' => $form->CreateView(),
));
}
我已经阅读了很多,但没有好结果。任何人吗?
答案 0 :(得分:0)
尝试改变这个:
$date = $request['form']['Date'];
到此:
$dateParsed = $request['form']['Date']['year'] . '-' . $request['form']['Date']['month'] . '-' . $request['form']['Date']['day'];
$date = new \DateTime($dateParsed);
答案 1 :(得分:0)
你必须检查你的类,什么是类使用:
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
********
答案 2 :(得分:0)
有效的解决方案是:
->add('Date',DateTimeType::class)
而不是:
awk '{ if(!/\\r\\n$/){ sep=""; sub("\\\\n","",$0) } else sep=ORS; printf "%s%s",$0,sep }' file