diff --git a/fluxRSS/DAL/ArticleGateway.php b/fluxRSS/DAL/ArticleGateway.php index a36f565..ad5bba5 100755 --- a/fluxRSS/DAL/ArticleGateway.php +++ b/fluxRSS/DAL/ArticleGateway.php @@ -22,15 +22,16 @@ class ArticleGateway return $this->con->getResults(); } - public function addArticle(Article $article){ + public function addArticle(Article $article) + { $query = 'INSERT INTO Article VALUES (:id,:title,to_date(:date,"Dy, DD Mon YYYY"),:description,:guid,:link,:mediaContent,:provenance);'; - $this->con->executeQuery($query, array( ':id' => array($article->getId(), PDO::PARAM_STR), - ':title' => array($article->getTitle(), PDO::PARAM_STR), - ':date' => array($article->getDate(),PDO::PARAM_STR), - ':description' => array($article->getDescription(),PDO::PARAM_STR), - ':guid' => array($article->getGuid(),PDO::PARAM_STR), - ':link' => array($article->getLink(),PDO::PARAM_STR), - ':mediaContent' => array($article->getMediaContent(),PDO::PARAM_STR), - ':provenance' => array($article->getProvenance(),PDO::PARAM_INT))); + $this->con->executeQuery($query, array(':id' => array($article->getId(), PDO::PARAM_STR), + ':title' => array($article->getTitle(), PDO::PARAM_STR), + ':date' => array($article->getDate(), PDO::PARAM_STR), + ':description' => array($article->getDescription(), PDO::PARAM_STR), + ':guid' => array($article->getGuid(), PDO::PARAM_STR), + ':link' => array($article->getLink(), PDO::PARAM_STR), + ':mediaContent' => array($article->getMediaContent(), PDO::PARAM_STR), + ':provenance' => array($article->getProvenance(), PDO::PARAM_INT))); } } \ No newline at end of file diff --git a/fluxRSS/DAL/Connection.php b/fluxRSS/DAL/Connection.php index 8be3ee1..1ca9c27 100755 --- a/fluxRSS/DAL/Connection.php +++ b/fluxRSS/DAL/Connection.php @@ -15,8 +15,13 @@ class Connection extends PDO */ public function __construct(string $dsn, string $username, string $password) { - parent::__construct($dsn, $username, $password); - $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try{ + parent::__construct($dsn, $username, $password); + $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + }catch (Exception $e){ + throw new Exception("PDO error con"); + } + } /** diff --git a/fluxRSS/controleur/Controleur.php b/fluxRSS/controleur/Controleur.php index ca4318e..81a6bee 100755 --- a/fluxRSS/controleur/Controleur.php +++ b/fluxRSS/controleur/Controleur.php @@ -3,13 +3,13 @@ namespace controleur; use model\ArticleModel; + class Controleur { public function __construct() { global $twig; // nécessaire pour utiliser variables globales session_start(); - $tabArticle[] = ArticleModel::getArticles(); //debut //on initialise un tableau d'erreur @@ -30,6 +30,7 @@ class Controleur //mauvaise action default: + $tabArticle[] = ArticleModel::getArticles(); $dVueEreur[] = "Erreur d'appel php"; $dataview = ['Article'=> $tabArticle]; echo $twig->render('listArticle.html', ['tabArticle' => $dataview, 'dVueErreur'=>$dVueEreur]); @@ -55,8 +56,9 @@ class Controleur $dVue = [ 'nom' => '', 'age' => 0, + 'data' => ArticleModel::getArticles(), ]; - echo $twig->render('vuephp1.html', [ + echo $twig->render('listArticle.html', [ 'dVue' => $dVue ]); } @@ -74,7 +76,7 @@ class Controleur $model = new \metier\Simplemodel(); $data = $model->get_data(); */ - + $dVue = [ 'nom' => $nom, 'age' => $age, diff --git a/fluxRSS/model/ArticleModel.php b/fluxRSS/model/ArticleModel.php index 4caf73a..bcb25a1 100755 --- a/fluxRSS/model/ArticleModel.php +++ b/fluxRSS/model/ArticleModel.php @@ -4,17 +4,17 @@ namespace model; use DAL; use metier; -require_once "config/config.php"; class ArticleModel { public static function getArticles() : array { - $gwArticle = new DAL\ArticleGateway(new DAL\Connection( $base, $login, $mdp)); + $gwArticle = new DAL\ArticleGateway(new DAL\Connection( 'mysql:host = localhost; dbname = dbrorossetto', 'rorossetto','tpphp')); $res = $gwArticle->getAllArticles(); foreach($res as $row){ $tabArticle[] = new metier\Article($row['id'], $row['title'],$row['datePub'],$row['description'],$row['guid'],$row['link'],$row['mediaContent'],$row['provenance'] ); } return $tabArticle; } + } \ No newline at end of file diff --git a/fluxRSS/templates/listArticle.html b/fluxRSS/templates/listArticle.html index c3dbaa6..b794cb4 100755 --- a/fluxRSS/templates/listArticle.html +++ b/fluxRSS/templates/listArticle.html @@ -5,7 +5,7 @@ All Articles -{% for value in tabArticle.Article %} +{% for value in dataview.tabArticle.Article %}

{{value}}

{% endfor %}