listArticle(); break; case 'connection': $this->connection();; break; case 'deconnection': $this->deconnection(); break; case 'validationFormulaire': $this->ValidationFormulaire($dVueEreur); break; //mauvaise action default: $dVueEreur[] = "Erreur d'appel php"; echo $twig->render('erreur.html', ['dVueErreur'=>$dVueEreur, 'isAdmin' => AdminModel::isAdmin()]); break; } } catch (\PDOException $e) { //si erreur BD, pas le cas ici $dVueEreur[] = 'Erreur PDO : ' . $e->getMessage(); echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } catch (\Exception $e2) { $dVueEreur[] = 'Erreur : ' . $e2->getMessage(); echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]); } //fin exit(0); }//fin constructeur public function listArticle() { global $twig; $articleModel = new ArticleModel(); $dVue = [ 'data' => $articleModel->getArticles() ]; echo $twig->render('listArticle.html', [ 'dVue' => $dVue, 'isAdmin' => AdminModel::isAdmin() ]); } /** * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError * @throws \Twig\Error\LoaderError */ public function connection(){ global $twig; // nécessaire pour utiliser variables globales if (AdminModel::isAdmin()) { $this->listArticle(); } else { echo $twig->render('Connection.html'); if (isset($_POST['username']) && isset($_POST['password'])) { $this->login(); } } } public function deconnection(){ AdminModel::deconnection(); $this->listArticle(); } /** * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError * @throws \Twig\Error\LoaderError * @throws \Exception */ public function login(){ $username = $_POST['username']; $password = $_POST['password']; $adminModel = new AdminModel(); $admin = $adminModel->connection($username, $password); if ($admin != null) { $this->listArticle(); } else{ $this->connection(); } } public function ValidationFormulaire(array $dVueEreur) { global $twig; // nécessaire pour utiliser variables globales //si exception, ca remonte !!! $nom = $_POST['txtNom']; // txtNom = nom du champ texte dans le formulaire $age = $_POST['txtAge']; \config\Validation::val_form($nom, $age, $dVueEreur); /* $model = new \metier\Simplemodel(); $data = $model->get_data(); */ $dVue = [ 'nom' => $nom, 'age' => $age, //'data' => $data, ]; echo $twig->render('Connection.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); } }//fin class