0

I have this code that uses a raw SQL query inside my controller:

        $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();

This code then passes the data to the view which is then used in a drop down date picker. However, no results are passed to the view even though running that SQL query on the database returns the results I need. What am I missing in order to pass this data to the view?

2
  • Seems work fine to me. How do you pass the data to the view? BTW: you can just do $this->get('database_connection')->fetchAll('...'); Commented Jan 4, 2015 at 10:56
  • Provide the relevant code how you are passing data to view ? Commented Jan 4, 2015 at 10:58

1 Answer 1

2

$activeDate->execute(); $activeDate->fetchAll(); This code then passes the data to the view ...

this code doesn't pass the data to view, you have to pass the data to view by array option in render method..

something like this:

$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
]);
Sign up to request clarification or add additional context in comments.

3 Comments

Or just return array with data, and template name is equal to your action name.
Only if you are using the @Template annotation.
This is correct, and it was exactly what I was doing. The issue was down to a memory issue on my development server which was preventing the query to run correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.