这是我在 MessageRepository 中的 DQL 查询:
public function getLastByIdAndByType($id_employee, $type)
{
$query = $this->_em->createQuery('SELECT MAX(m.sentAt), m.recipient, m.author, m.subject, m.body, m.type FROM MyBundle:Message m JOIN m.employee e WHERE e.id = :id_employee AND m.type = :type')
->setParameter('id_employee', $id_employee)
->setParameter('type', $type)
return $query->getSingleResult();
} </code>
In my controller :
$last_message=$em->getRepository('MyBundle:Message')->getLastByIdAndByType($id, $type);
In my view html.twig {{ last_message.sentAt }}
returns the error : Item "sentAt" for "Array" does not exist
While
{{ last_message.recipient }}
有效,但确实对于我的所有消息,收件人都是相同的。
我应该怎么做才能用 {{ last_message.sentAt }} 呈现最近的日期?非常感谢!