Afficher tableau dans view

Par Kyou, il y a 9 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.
J'ai la fonction suivante dans le controller :

public function notesEtudiant($id) { $this->set('notes', $this->Etudiant->find('all', array( 'fields' => '*', 'joins' => array( array( 'table' => 'notes', 'alias' => 'Note', 'type' => 'LEFT', 'conditions' => array('Note.etudiant_id = '. $id .'') ) ) ))); }

Je ne sais pas comment remplir ma view... Je ne comprend pas comment le set fonctionne..

<h1> FICHE ETUDIANT :</h1> <table> <tr> <th>Id</th> <th>Matière</th> <th>Note</th> </tr> <tr> <td><?php echo ... ?></td> <td><?php echo ... ?></td> <td><?php echo ... ?></td> </tr> </table>

Pourriez vous m'aider ?

Merci :)

3 réponses

Lartak, il y a 9 ans

Bonsoir.
La méthode set te permet d'envoyer une/des variable(s) à la vue, donc tu récupéres le contenu de ta variable normalement.
Exemple :

<h1> FICHE ETUDIANT :</h1> <table> <thead> <tr> <th>Id</th> <th>Matière</th> <th>Note</th> </tr> </thead> <tbody> <?php foreach ($notes as $note): ?> <tr> <td>...</td> <td>...</td> <td>...</td> </tr> <?php endforeach; ?> </tbody> </table>
Kyou, il y a 9 ans

Bonsoir, Merci de ta réponse. Le problème est que vu qu'il y a x notes dans ma table ( pas forcément à la même personne ) . Il m'affiche x fois la même note. Comment faire ?

romses, il y a 9 ans

Ajoute une clause DISTINCT (id) a ta requete