我有这个代码在我的控制器中使用原始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查询返回我需要的结果,也没有结果传递给视图。为了将这些数据传递给视图,我缺少什么?
答案 0 :(得分:2)
$ activeDate->执行(); $ activeDate->使用fetchall(); 然后,此代码将数据传递给视图...
此代码未传递数据进行查看,您必须将数据传递给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
]);