modification ArticleGateway, Connection, Controleur and view listArticle

feature/article
Roxane ROSSETTO 1 year ago
parent 8c10efc649
commit 08b0a4d906

@ -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),
$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)));
':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)));
}
}

@ -15,8 +15,13 @@ class Connection extends PDO
*/
public function __construct(string $dsn, string $username, string $password)
{
try{
parent::__construct($dsn, $username, $password);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (Exception $e){
throw new Exception("PDO error con");
}
}
/**

@ -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
]);
}

@ -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;
}
}

@ -5,7 +5,7 @@
<title>All Articles</title>
</head>
<body>
{% for value in tabArticle.Article %}
{% for value in dataview.tabArticle.Article %}
<p>{{value}}</p>
{% endfor %}
</body>

Loading…
Cancel
Save