我试图拉一个完整的用户列表进入一个表。
我有一个userStatistics的函数,我假设它允许我从DB输出所有用户行。
public function userStatistics(){
$stmtParams = array(
'status' => 'Confirm'
);
$andWhere = ' WHERE u.`created_at` <= NOW() - INTERVAL 7 DAY';
$query = $this->getEntityManager()->getConnection()->prepare("
SELECT
COUNT(u.`id`) AS regCount,
DATE_FORMAT(DATE(b.Days), '%a' ) AS regDate
FROM
(SELECT a.Days
FROM (
SELECT
curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY AS Days
FROM (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS a
CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS b
CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS c
) a
WHERE a.Days >= curdate() - INTERVAL 6 DAY) b
LEFT JOIN `user` u ON DATE_FORMAT(u.`created_at`, '%Y-%m-%d') = b.Days
GROUP BY b.Days
ORDER BY b.Days
");
$query->execute($stmtParams);
$result = $query->fetchAll();
return !empty($result) ? $result : array();
}
目前正在尝试与下面类似的格式。
{{%for user.userStatistics('$result') %}}
{{ user.id }}
{% endfor %}
{{%for user.userStatistics('$result') %}}
{{ user.id }}
{% endfor %}
{{ user.userStatistics }}
{{ user.id }}
两者都失败,出现服务器错误。
1条答案
按热度按时间6rqinv9w1#
我猜你的函数在你的仓库类中,所以你可以创建一个twig扩展来调用你的仓库函数,就像这样
然后用小树枝把它扔下去