0
$em = $this->getDoctrine()->getEntityManager();
$repository = $em->getRepository('UserBundle:items');
$items = $repository->findOneBy(
    array('isCancel' => false,
          'user' => $username,
          array('toDate' => 'ASC'));

我想添加比较功能

  where registeredtime > now()

我可以用 findOneBy 来比较句子吗?

或者我必须写整个sql?

4

2 回答 2

1

你可以这样做

$em = $this->getDoctrine()->getEntityManager();
$repository = $em->getRepository('UserBundle:items');
$items = $repository->findOneBy(
    array('isCancel' => false,
    'user' => $username,
    array('toDate' => 'ASC'));
$criteria = Criteria::create()->where(Criteria::expr()->gt("registeredtime", now()));
$filteredItems = $items->matching($criteria);
于 2013-05-01T11:39:34.697 回答
1

你可以试试:

...

$startDate = new DateTime();

$qb   = $repository->createQueryBuilder('e');
$event = $qb
    ->andWhere($qb->expr()->eq('e.start_date', ':start_date'))
    ->setParameter('start_date', $startDate)
    ->getQuery()
        ->getOneOrNullResult();
于 2013-05-01T11:40:01.603 回答