如何将原始 SQL 查询的结果传递到 Symfony2 中查看
How to pass results from raw SQL query to view in Symfony2
我有这段代码在我的控制器中使用原始 SQL 查询:
$sql1 = "SELECT completion_date FROM enviro_figures_upload GROUP BY YEAR(completion_date), MONTH(completion_date) DESC;";
$activeDate = $this->getDoctrine()->getManager()->getConnection()->prepare($sql1);
$activeDate->execute();
$activeDate->fetchAll();
此代码然后将数据传递到视图,然后在下拉日期选择器中使用该视图。但是,即使在数据库上运行 SQL 查询 returns 我需要的结果,也没有结果传递给视图。为了将此数据传递给视图,我缺少什么?
$activeDate->execute();
$activeDate->fetchAll();
This code then passes the data to the view ...
此代码不会将数据传递给查看,您必须在 render
方法中通过数组选项传递数据才能查看..
像这样:
$sql1 = "SELECT completion_date FROM enviro_figures_upload GROUP BY YEAR(completion_date), MONTH(completion_date) DESC;";
$activeDate = $this->getDoctrine()->getManager()->getConnection()->prepare($sql1);
$activeDate->execute();
$result = $activeDate->fetchAll();
return $this->render('TEMPLATE_PATH', [
'result' => $result
]);
我有这段代码在我的控制器中使用原始 SQL 查询:
$sql1 = "SELECT completion_date FROM enviro_figures_upload GROUP BY YEAR(completion_date), MONTH(completion_date) DESC;";
$activeDate = $this->getDoctrine()->getManager()->getConnection()->prepare($sql1);
$activeDate->execute();
$activeDate->fetchAll();
此代码然后将数据传递到视图,然后在下拉日期选择器中使用该视图。但是,即使在数据库上运行 SQL 查询 returns 我需要的结果,也没有结果传递给视图。为了将此数据传递给视图,我缺少什么?
$activeDate->execute(); $activeDate->fetchAll(); This code then passes the data to the view ...
此代码不会将数据传递给查看,您必须在 render
方法中通过数组选项传递数据才能查看..
像这样:
$sql1 = "SELECT completion_date FROM enviro_figures_upload GROUP BY YEAR(completion_date), MONTH(completion_date) DESC;";
$activeDate = $this->getDoctrine()->getManager()->getConnection()->prepare($sql1);
$activeDate->execute();
$result = $activeDate->fetchAll();
return $this->render('TEMPLATE_PATH', [
'result' => $result
]);