So I have this simple form in symfony where I only have 3 fields. All ids working to here one entity that is not on form but it's in the DB is column df_date and it's type DATE in DB.
Here is that entity:
/**
* @ORM\Column(type="date")
* @ORM\Id
*/
protected $df_date;
/**
* Set df_date
*
* @param \DateTime $dfDate
* @return WeatherSpecials
*/
public function setDfDate($dfDate)
{
$this->df_date = $dfDate;
return $this;
}
/**
* Get df_date
*
* @return \DateTime
*/
public function getDfDate()
{
return $this->df_date;
}
Controller:
public function ajax_weather_specialsAction(Request $request, $main_id)
{
$params = array();
if (!$main_id) {
/*
$repository = $this->getDoctrine()
->getRepository('AppBundle:WeatherSpecials');
$weather_specials = $repository->find($main_id);
*/
} else {
$weather_specials = new WeatherSpecials;
}
$form = $this->createFormBuilder($weather_specials)
->add('df_weather', 'choice', array(
'choices' => array(
null, 'SU', 'PC', 'CL', 'RN'
),
'label' => false, 'required' => true,
))
->add('df_temptur', 'number', array('label' => false, 'required' => true))
->add('df_specday', 'text', array('label' => false, 'required' => false))
->add('save', 'submit', array('attr' => array('class' => 'btn btn-primary')))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($weather_specials);
// How to set df_date here???
$em->flush();
}
}
$data['status'] = 'success';
$data['html'] = $this->render('sales_tabs/weather_specials.twig', array('form' => $form->createView()))->getContent();
return new JsonResponse($data);
}
And the question is, how to set the df_date before I persist that form to the DB?