php - Object with Date is saved with the wrong date and format -
i'm saving date symfony 3 , bootstrap-datepicker.
if fill out form expect save date, 04/25/2017 in case.
what want in datatabse this: 04/25/2017.
instead in dump:
2017-01-25 00:04.000000
and in database:
2017-01-25
dump result:
database value:
playlogcontroller:
<?php namespace appbundle\controller; use appbundle\entity\playlog; use appbundle\entity\game; use symfony\bundle\frameworkbundle\controller\controller; use sensio\bundle\frameworkextrabundle\configuration\method; use sensio\bundle\frameworkextrabundle\configuration\route; use symfony\component\httpfoundation\request; /** * playlog controller. * * @route("playlog") */ class playlogcontroller extends controller { /** * lists playlog entities. * * @route("/", name="playlog_index") * @method("get") */ public function indexaction() { $em = $this->getdoctrine()->getmanager(); $playlogs = $em->getrepository('appbundle:playlog')->findall(); return $this->render('playlog/index.html.twig', array( 'playlogs' => $playlogs, )); } /** * creates new playlog entity. * * @route("/{gameid}/new", name="playlog_new") * @method({"get", "post"}) */ public function newaction(request $request, $gameid) { $playlog = new playlog(); $em = $this->getdoctrine()->getmanager(); $game = $em ->getrepository(game::class)->find($gameid); $playlog->setgame($game); $form = $this->createform('appbundle\form\playlogtype', $playlog); $form->handlerequest($request); if ($form->issubmitted() && $form->isvalid()) { /* @var $playlog playlog */ $playlog = $form->getdata(); // echo $playlog->getgame()->getid() .'!'; $em->persist($playlog); $em->flush(); } return $this->render('playlog/new.html.twig', array( 'playlog' => $playlog, 'form' => $form->createview(), )); } /** * finds , displays playlog entity. * * @route("/{id}", name="playlog_show") * @method("get") */ public function showaction(playlog $playlog) { $deleteform = $this->createdeleteform($playlog); return $this->render('playlog/show.html.twig', array( 'playlog' => $playlog, 'delete_form' => $deleteform->createview(), )); } /** * displays form edit existing playlog entity. * * @route("/{id}/edit", name="playlog_edit") * @method({"get", "post"}) */ public function editaction(request $request, playlog $playlog) { $deleteform = $this->createdeleteform($playlog); $editform = $this->createform('appbundle\form\playlogtype', $playlog); $editform->handlerequest($request); if ($editform->issubmitted() && $editform->isvalid()) { $this->getdoctrine()->getmanager()->flush(); return $this->redirecttoroute('playlog_edit', array('id' => $playlog->getid())); } return $this->render('playlog/edit.html.twig', array( 'playlog' => $playlog, 'edit_form' => $editform->createview(), 'delete_form' => $deleteform->createview(), )); } /** * deletes playlog entity. * * @route("/{id}", name="playlog_delete") * @method("delete") */ public function deleteaction(request $request, playlog $playlog) { $form = $this->createdeleteform($playlog); $form->handlerequest($request); if ($form->issubmitted() && $form->isvalid()) { $em = $this->getdoctrine()->getmanager(); $em->remove($playlog); $em->flush(); } return $this->redirecttoroute('playlog_index'); } /** * creates form delete playlog entity. * * @param playlog $playlog playlog entity * * @return \symfony\component\form\form form */ private function createdeleteform(playlog $playlog) { return $this->createformbuilder() ->setaction($this->generateurl('playlog_delete', array('id' => $playlog->getid()))) ->setmethod('delete') ->getform() ; } }
playlogtype:
<?php namespace appbundle\form; use appbundle\entity\playlog; use symfony\component\form\extension\core\type\datetype; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolver; class playlogtype extends abstracttype { /** * {@inheritdoc} */ public function buildform(formbuilderinterface $builder, array $options) { $builder->add('date', datetype::class, array( 'widget' => 'single_text', 'html5' => false, 'attr' => ['class' => 'js-datepicker'], 'format' => 'mm/dd/yyyy' ) ); } /** * {@inheritdoc} */ public function configureoptions(optionsresolver $resolver) { $resolver->setdefaults(array( 'data_class' => playlog::class )); } /** * {@inheritdoc} */ public function getblockprefix() { return 'appbundle_playlog'; } }
the script use datepicker:
<script type="text/javascript"> $(document).ready(function () { $('.js-datepicker').datepicker({ format: 'mm/dd/yyyy' }); }); </script>
format must 'mm/dd/yyyy'
. mm
minutes, why time 00:04
in record.
Comments
Post a Comment