我使用以下代码使用学说本机查询一些数据:
$sql = "SELECT count(type) AS notifications,
count(DISTINCT subject) AS users,
count(DISTINCT object_activity) AS activities,
count(DISTINCT object_activity_relationship) AS relationships,
type,
min(created) as oldest,
max(created) as latest "
."FROM notification n "
."WHERE target_user='".$user->id."' AND notification_read=0 "
."GROUP BY type "
."ORDER BY latest ";
$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
$rsm->addScalarResult('type', 'type');
$rsm->addScalarResult('oldest', 'oldest');
$rsm->addScalarResult('latest', 'latest');
$rsm->addScalarResult('users', 'users');
$rsm->addScalarResult('notifications', 'notifications');
$rsm->addScalarResult('activities', 'activities');
$rsm->addScalarResult('relationships', 'relationships');
$query = $this->_em->createNativeQuery($sql, $rsm);
return $query->getResult();
创建的字段是数据库中的 DateTime 字段,目前,它给了我这样的日期:
2012-08-22 14:45:37
我想更改格式,有没有办法告诉教义如何使用结果集映射对其进行格式化?我知道我可以用 php 做到这一点,但我想先看看我是否可以这样做。