Exemple #1
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]);
}
?>
Exemple #2
0
 public function addStudent()
 {
     $vue = new VueEtu(Groupe::all()->toArray());
     $vue->showForm();
 }
Exemple #3
0
 /**
  * affiche les groupes
  */
 public function groupes()
 {
     $listg = Groupe::all();
     $vue = new VueEtu($listg->toArray());
     $vue->render(1);
 }