par
ouckileou » 12 févr. 2013, 01:48
Voici donc ma requête:
public function loadAll($semesterId) {
$q = $this
->createQueryBuilder('c')
->addSelect('c.id as course_id, c.dayOfWeek, c.startTime, c.endTime, c.alternateStartdate, c.alternateEnddate')
->addSelect('r.name as classroom, c2.label as classlevel')
->addSelect('t.id as teacher_id, t.lastName as teacher_lastName, t.firstName as teacher_firstName')
->innerJoin('c.teachers', 't')
->innerJoin('c.classLevel', 'c2')
->innerJoin('c.classRoom', 'r')
->innerJoin('c.semester', 's')
->where('s.id = :semesterId')
->add('orderBy', 'c.dayOfWeek ASC, c.startTime ASC')
->setParameter('semesterId', $semesterId)
->getQuery()
;
$results = $q->execute(array(), Query::HYDRATE_ARRAY);
return $results;
}
Le tableau généré:
array(6) {
[0] =>
array(13) {
[0] =>
array(6) {
'id' =>
int(326)
'dayOfWeek' =>
int(2)
'startTime' =>
class DateTime#1902 (3) {
...
}
'endTime' =>
class DateTime#1900 (3) {
...
}
'alternateStartdate' =>
NULL
'alternateEnddate' =>
NULL
}
'course_id' =>
int(326)
'dayOfWeek' =>
int(2)
'startTime' =>
class DateTime#1898 (3) {
public $date =>
string(19) "2013-02-11 10:00:00"
public $timezone_type =>
int(3)
public $timezone =>
string(16) "America/New_York"
}
'endTime' =>
class DateTime#1888 (3) {
public $date =>
string(19) "2013-02-11 11:30:00"
public $timezone_type =>
int(3)
public $timezone =>
string(16) "America/New_York"
}
'alternateStartdate' =>
NULL
'alternateEnddate' =>
NULL
'classroom' =>
string(14) "Salle de cours"
'classlevel' =>
string(2) "A2"
'teacher_id' =>
int(3554)
'teacher_lastName' =>
string(7) "Keating"
'teacher_firstName' =>
string(4) "John"
'teachers' =>
array(1) {
[0] =>
array(3) {
...
}
}
}
[...]}
Le bout du template concerné:
<ul>
{% for teacher in entity['teachers'] %}
<li><a href="{{ path('teacher_show', { 'id': teacher['teacher_id'] }) }}">{{ teacher['teacher_lastName'] }}</a></li>
{% endfor %}
</ul>
Et le message d'erreur que j'ai :
Key "teachers" for array with keys "0, course_id, dayOfWeek, startTime, endTime, alternateStartdate, alternateEnddate, classroom, classlevel, teacher_id, teacher_lastName, teacher_firstName" does not exist in /home/guillaume/public_html/Virgule/src/Virgule/Bundle/MainBundle/Resources/views/Course/index.html.twig at line 30
Donc je ne comprends pas bien, j'ai pourtant l'impression que dans la cellule 'teachers' j'ai un autre tableau sur lequel je devrais pouvoir itérer facilement... une idée ?
Voici donc ma requête:
[php] public function loadAll($semesterId) {
$q = $this
->createQueryBuilder('c')
->addSelect('c.id as course_id, c.dayOfWeek, c.startTime, c.endTime, c.alternateStartdate, c.alternateEnddate')
->addSelect('r.name as classroom, c2.label as classlevel')
->addSelect('t.id as teacher_id, t.lastName as teacher_lastName, t.firstName as teacher_firstName')
->innerJoin('c.teachers', 't')
->innerJoin('c.classLevel', 'c2')
->innerJoin('c.classRoom', 'r')
->innerJoin('c.semester', 's')
->where('s.id = :semesterId')
->add('orderBy', 'c.dayOfWeek ASC, c.startTime ASC')
->setParameter('semesterId', $semesterId)
->getQuery()
;
$results = $q->execute(array(), Query::HYDRATE_ARRAY);
return $results;
}[/php]
Le tableau généré:
[php]array(6) {
[0] =>
array(13) {
[0] =>
array(6) {
'id' =>
int(326)
'dayOfWeek' =>
int(2)
'startTime' =>
class DateTime#1902 (3) {
...
}
'endTime' =>
class DateTime#1900 (3) {
...
}
'alternateStartdate' =>
NULL
'alternateEnddate' =>
NULL
}
'course_id' =>
int(326)
'dayOfWeek' =>
int(2)
'startTime' =>
class DateTime#1898 (3) {
public $date =>
string(19) "2013-02-11 10:00:00"
public $timezone_type =>
int(3)
public $timezone =>
string(16) "America/New_York"
}
'endTime' =>
class DateTime#1888 (3) {
public $date =>
string(19) "2013-02-11 11:30:00"
public $timezone_type =>
int(3)
public $timezone =>
string(16) "America/New_York"
}
'alternateStartdate' =>
NULL
'alternateEnddate' =>
NULL
'classroom' =>
string(14) "Salle de cours"
'classlevel' =>
string(2) "A2"
'teacher_id' =>
int(3554)
'teacher_lastName' =>
string(7) "Keating"
'teacher_firstName' =>
string(4) "John"
'teachers' =>
array(1) {
[0] =>
array(3) {
...
}
}
}
[...]}[/php]
Le bout du template concerné:
[php] <ul>
{% for teacher in entity['teachers'] %}
<li><a href="{{ path('teacher_show', { 'id': teacher['teacher_id'] }) }}">{{ teacher['teacher_lastName'] }}</a></li>
{% endfor %}
</ul>[/php]
Et le message d'erreur que j'ai :
[quote]Key "teachers" for array with keys "0, course_id, dayOfWeek, startTime, endTime, alternateStartdate, alternateEnddate, classroom, classlevel, teacher_id, teacher_lastName, teacher_firstName" does not exist in /home/guillaume/public_html/Virgule/src/Virgule/Bundle/MainBundle/Resources/views/Course/index.html.twig at line 30 [/quote]
Donc je ne comprends pas bien, j'ai pourtant l'impression que dans la cellule 'teachers' j'ai un autre tableau sur lequel je devrais pouvoir itérer facilement... une idée ?