這是我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}}? 非常感謝!