symfony - form use curremt datatime -
i have form datetyoe field
$builder->add('dataspesa',datetype::class,array( 'data' => new \datetime("now"), 'label'=>false, 'widget'=>'single_text', 'attr' => array('style' => 'width: 100%;margin-top:10px;', 'class' => 'js-datepicker' ) ))
now want use form in edit form , use use save datetime .. try in way don't work , i'm sure best way
if($options['data']->getdataspesa()){ $data_spesa=$options['data']['dataspesa']->getdata(); ->>> syntax error don't understand correct way have datetime value }else{ $data_spesa=new \datetime("now"); } ->add('dataspesa',datetype::class,array( 'label'=>false, 'data'=>$data_spesa, -> correct way??? 'widget'=>'single_text', 'attr' => array('style' => 'width: 100%;margin-top:10px;', 'class' => 'js-datepicker' ) ))
to better understand .. use form in 2 controller. in home page
/** * @route("/", name="homepage") */ public function indexaction(request $request) { // crea nuovo $voce_costo = new vocecosto(); $form = $this->createform(vocecostotype::class, $voce_costo); $form->handlerequest($request); if ($form->issubmitted() && $form->isvalid()) { return $this->render('default/add/vocecosto.html.twig', array( 'form' => $form->createview() )); }
in want date set default current date
in other controller (edit controller)
/** * @route("/edit/{id_vocecosto}", name="edit_voce") */ public function editvocecostoaction(request $request,$id_vocecosto) { // crea nuovo $voce_costo = $this->getdoctrine() ->getrepository('appbundle:vocecosto') ->find($id_vocecosto); $form = $this->createform(vocecostotype::class, $voce_costo); $form->handlerequest($request); if ($form->issubmitted() && $form->isvalid()) { } return $this->render('default/edit/voce_costo.html.twig', array( 'form' => $form->createview() )); }
here want value data saved in database
Comments
Post a Comment