这是我DQL查询在MessageRepository: DQL查询,MAX功能和getSingleResult
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);
在我看来html.twig {{ last_message.sentAt }}
返回错误:Item "sentAt" for "Array" does not exist
虽然
{{last_message.recipient}}
的作品,但它是真的,我的所有邮件收件人是一样的。
我应该怎么做来呈现最新的日期与{{last_message.sentAt}}? 非常感谢!