I have a person (Employee) search that is supposed to return a list of people by name, surname, date of birth and some other parameters. the search works fine for every parameter exempt for the date parameters, like date of birth. my controller code is this:
$aWorker = new Worker();
$searchWorkerForm = $this->createFormBuilder($aWorker)
->add('omang', 'text', array('required' => false))
->add('workerName', 'text', array('required' => false))
->add('workerSurname', 'text', array('required' => false))
->add('birthDay', 'date',
array('required' => false, 'years' => range(1950, 2020)))
->add('dateOfEmployment', 'date', array('required' => false))
->add('search', 'submit')
->getForm();
//Handle Request
if ($request->getMethod() == 'POST')
$searchWorkerForm->handleRequest($request);
$aWorkerList = $this->getDoctrine()
->getRepository('OsdRetireBundle:Worker')
->findByPersonDetails($aWorker->getOmang(),
$aWorker->getWorkerName(),
$aWorker->getWorkerSurname(),
$aWorker->getBirthDay(),
$aWorker->getDateOfEmployment());
//...
The findByPersonDetails function is this:
public function findByPersonDetails($omang, $WorkerName,
$workerSurname, $birthDay, $dateOfEmployment){
$qqq = $this->getEntityManager()
->createQuery('SELECT w FROM OsdRetireBundle:Worker w
WHERE w.omang LIKE :omang
AND w.workerName LIKE :WorkerName
AND w.workerSurname LIKE :workerSurname
AND w.birthDay LIKE :birthDay
AND w.dateOfEmployment LIKE :dateOfEmployment')
->setParameter('omang', '%'.$omang.'%')
->setParameter('WorkerName', '%'.$WorkerName.'%')
->setParameter('workerSurname', '%'.$workerSurname.'%')
->setParameter('birthDay', '%'.$birthDay.'%')
->setParameter('dateOfEmployment', '%'.$dateOfEmployment.'%')
->getResult();
return $qqq;
}
The error is the following:
Catchable Fatal Error: Object of class DateTime could not be converted to string in /var/www/Org/src/Osd/RetireBundle/Entity/WorkerRepository.php line 27
500 Internal Server Error - ContextErrorException
Am I supposed to convert with my own function the date to string? if so Where should I do it to make it reusable? any working example? I thought that Doctrine was able to do this automatically. Thak you in advenced.