Exemple #1
0
 /**
  * Affiche un groupe ainsi que ses étudiants
  */
 public function showGroup($id)
 {
     try {
         $id = intval($id);
         $s = Groupe::findOrFail($id);
         // renvois une exception si le groupe n'existe pas.
         $vue = new VueEtu($s);
         $vue->render(2);
     } catch (ModelNotFoundException $e) {
         echo "Cet etudiant n'existe pas";
     }
 }
Exemple #2
0
 public function addStudent()
 {
     $vue = new VueEtu(Groupe::all()->toArray());
     $vue->showForm();
 }
Exemple #3
0
        // on s'évite des possibles failles sql.
        $s = Student::findOrFail($id);
        // renvois une exception si l'étudiant n'existe pas.
        showItem($s->toArray());
    } catch (ModelNotFoundException $e) {
        echo "Cet etudiant n'existe pas";
    }
} elseif (isset($_GET['showStudents'])) {
    // on veux afficher tous les étudiants.
    foreach (Student::all()->toArray() as $item) {
        showItem($item);
        echo "-----<br>";
    }
} elseif (isset($_GET['showGroups'])) {
    // on veux afficher tous les groupes.
    foreach (Groupe::all()->toArray() as $item) {
        showItem($item);
        echo "-----<br>";
    }
} elseif (isset($_GET['createStudent'])) {
    // on veux crer un étudiant
    $names = [["Alex", "Rose"], ["Art", "Rowland"], ["Barry", "Tad Keller"], ["Basil", "Abraham Lancaster"], ["Bob", "Garza"]];
    $name = $names[rand(0, count($names) - 1)];
    // on choisi un nom au hasard.
    /*
     * on ajoute l'étudiant dans le 1er groupe.
     */
    Student::create(["prenom" => $name[0], "nom" => $name[1], "id_gpe" => 1]);
}
?>