En el codigo del controller he setteado la fecha de creación a la fecha actual:
Código PHP:
/**
* Creates a new SchoolRecord entity.
*
* @Route("/create", name="admission_school_record_applicant_create")
* @Method("POST")
* @Template("ABCAdmissionBundle:Applicant:Applicant.html.twig")
*/
public function createAction(Request $request)
{
$session = $this->getRequest()->getSession();
$appId=$session->get('applicant');
$entity = new SchoolRecord();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager("admission");
$applicantObject = $em->getRepository('ABCAdmissionBundle:Applicant')->find($appId);
$entity->setApplicant($applicantObject);
$app=$entity->getApplicant();
$entity->setCreatedDate(new DateTime());
// $entity->setIsCurrent('true');
if ($form->isValid()) {
$em->persist($entity);
$em->flush();
$session = $this->getRequest()->getSession();
$session->set('step',3);
$session->set('applicant',$app->getId());
return $this->redirect($this->generateUrl('admission_applicants'));
}
$session->set('step',2);
$session->set('applicant',$app->getId());
return $this->redirect($this->generateUrl('admission_applicants'));
/* return array(
'entity' => $entity,
'form' => $form->createView(),
);*/
}
Código PHP:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('schoolName','text',array('label'=>'School name - Nombre del colegio *'))
->add('fromDate','date',array('format' => 'dd-MMM-yyyy',
'years'=>range((date("Y")-14), date("Y")),
'label'=>'Attended from - Periodo desde'))
->add('toDate','date',array('format' => 'dd-MMM-yyyy',
'years'=>range((date("Y")-14), date("Y")),
'label'=>'Attended to - Periodo hasta'))
->add('headName','text',array('label'=>'Name of the Head - Nombre del Director'))
->add('phoneNumber','text',array('label'=>'Phone number - Teléfono'))
->add('eMail','text',array('label'=>'E-mail - Correo electrónico'))
->add('isCurrent','choice',array(
'label'=>'Information of present school - Información del colegio actual *',
'empty_value' => 'Choose an option',
'choices'=> array(
'true' => 'Yes / Si',
'false' => 'No',
)))
// ->add('createdDate')
->add('address','entity',
array('label'=>'Select a address *',
'class'=>'ABCAdmissionBundle:Addresses',
'property'=>'id'
))
;
}
Código HTML:
{% extends "ABCAdmissionBundle::layoutAppForm.html.twig" %} {% block title %} School Information Form {% endblock %} {% block contenido %} {{form_start(form)}} {{form_errors(form)}} <div class="row-fluid"> <div class="span12"> {{form_row(form.schoolName, {'attr': {'class': 'span11'}}) }} {{ form_row(form.headName, {'attr': {'class': 'span11'}}) }} </div> </div> <div class="row-fluid"> <div class="span6"> {{form_label(form.fromDate)}} {{form_widget(form.fromDate.day,{'attr': {'class': 'span3'}}) }} {{form_widget(form.fromDate.month,{'attr': {'class': 'span3'}}) }} {{form_widget(form.fromDate.year,{'attr': {'class': 'span3'}}) }} {{form_row(form.phoneNumber)}} {{form_row(form.address)}} </div> <div class="span6"> {{form_label(form.toDate)}} {{form_widget(form.toDate.day, {'attr': {'class': 'span3'}}) }} {{form_widget(form.toDate.month,{'attr': {'class': 'span3'}}) }} {{form_widget(form.toDate.year,{'attr': {'class': 'span3'}}) }} {{form_row(form.eMail)}} {{form_row(form.isCurrent)}} </div> </div> {{form_widget(form.save)}} {{form_end(form)}} {% endblock %}