存储库中的方法
public function getDays(\DateTime $firstDateTime, \DateTime $lastDateTime)
{
$qb = $this->getEntityManager()->createQueryBuilder()
->select('c')
->from('ProjectBundle:Calendar', 'c')
->where('c.date BETWEEN :firstDate AND :lastDate')
->setParameter('firstDate', $firstDateTime)
->setParameter('lastDate', $lastDateTime)
;
$result = $qb->getQuery()->getResult();
return $result;
}
和行动
public function calendarAction()
{
$currentMonthDateTime = new \DateTime();
$firstDateTime = $currentMonthDateTime->modify('first day of this month');
$currentMonthDateTime = new \DateTime();
$lastDateTime = $currentMonthDateTime->modify('last day of this month');
$days = $this->getDoctrine()
->getRepository('ProjectBundle:Calendar')
->getDays($firstDateTime, $lastDateTime);
return ['days' => $days];
}