1

I have made the following DQL call:

"SELECT SUBSTRING(e.sDateStart, 1, 4) as year
 FROM contrastBundle:Exhibition e
 WHERE e.sDateStart < :dateStart
 GROUP BY year
 ORDER BY year DESC"

which basically returns what I need but in the following form:

array(3) {
  [0]=>
  array(1) {
    ["year"]=>
    string(4) "2007"
  }
  [1]=>
  array(1) {
    ["year"]=>
    string(4) "2006"
  }
  [2]=>
  array(1) {
    ["year"]=>
    string(4) "2005"
  }
}

This makes it quite annoying to work with it.

EDIT In:

{% for eachyear in years %}
    <a {% if year == eachyear.year %}class="active"{% endif %} href="{{path('exhibitions', {'year' : eachyear.year })}}">{{ eachyear.year }}</a>
{% endfor %}

I can access the strings with eachyear.year but is an ugly solution.

I was wondering which would be the best solution to this, i'd especially like to process the array i get from the call so that it is basically an array of years. pop_array() and similar don't seem to be helpful. I also tried to hydrate the output of the call, getArrayResult() and getScalarResult() will all return the same output.

AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
mezod
  • 2,313
  • 3
  • 21
  • 31
  • 2
    This question was already answered here: http://stackoverflow.com/questions/11657835/how-to-get-a-one-dimensional-scalar-array-as-a-doctrine-dql-query-result – stefreak Mar 29 '13 at 11:51

0 Answers0