First of all thank you for reading and trying to help me. I'm new in symfony.
I have an entity with property FechaAlta (SingUpDate). I want to save the user sing up date
/**
* @var date
*
* @ORM\Column(name="fechaAlta", type="datetime")
*/
private $fechaAlta;
/**
* Set fechaAlta
*
* @return Promotor
*/
public function setFechaAlta()
{
$this->fechaAlta = new \DateTime('now');
return $this;
}
I'd like to know what is the best way to save this date without having a hidden field on the form.
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nombre')
#->add('slug')
->add('fechaAlta')
;
}
I have tried removing the form field "fechaAlta" but keep get the following error
An exception occurred while executing 'INSERT INTO Promotor (nombre, slug, fechaAlta) VALUES (?, ?, ?)' with params {"1":"Prueba","2":"prueba","3":null}:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fechaAlta' cannot be null
In the newAction() i call $promotor->setFechaAlta(); that should save the current date.
public function newAction()
{
$promotor = new Promotor();
$promotor->setFechaAlta();
$form = $this->createForm(new PromotorType(), $promotor);
return $this->render('PromotorBundle:Promotor:new.html.twig', array(
'entity' => $promotor,
'form' => $form->createView(),
));
}
Thank you so much