💩 retour stade fonctionnel

pull/6/head
maxime.point2 1 year ago
parent 8fdadf16f1
commit 11f90fc96e

@ -2,7 +2,9 @@
namespace DAL; namespace DAL;
use Exception;
use PDO; use PDO;
use Twig\Error\Error;
class Connection extends PDO class Connection extends PDO
{ {
@ -12,26 +14,39 @@ class Connection extends PDO
* @param string $dsn * @param string $dsn
* @param string $username * @param string $username
* @param string $password * @param string $password
* @throws Exception
*/ */
public function __construct(string $dsn, string $username, string $password) public function __construct(string $dsn, string $username, string $password)
{ {
parent::__construct($dsn, $username, $password); try{
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); parent::__construct($dsn, $username, $password);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (\PDOException $e){
throw new Exception("PDO error con");
}
catch (Error $e){
throw new Error("Error PDO");
}
} }
/** /**
* @param string $query to execute * @param string $query to execute
* @param array $parameters to bind * @param array $parameters to bind
* @return bool Returns `true` on success, `false` otherwise * @return bool Returns `true` on success, `false` otherwise
* @throws Exception
*/ */
public function executeQuery(string $query, array $parameters = []): bool public function executeQuery(string $query, array $parameters = []): bool
{ {
$this->stmt = parent::prepare($query); try{
foreach ($parameters as $name => $value) { $this->stmt = parent::prepare($query);
$this->stmt->bindValue($name, $value[0], $value[1]); foreach ($parameters as $name => $value) {
} $this->stmt->bindValue($name, $value[0], $value[1]);
}
return $this->stmt->execute(); return $this->stmt->execute();
}catch (\PDOException $e){
throw new Exception("PDO error");
}
} }
/** /**

@ -51,12 +51,12 @@ class Controleur
public function Reinit() public function Reinit()
{ {
global $twig; // nécessaire pour utiliser variables globales global $twig; // nécessaire pour utiliser variables globales
$dVue = [ $dVue = [
'nom' => '', 'nom' => '',
'age' => 0, 'age' => 0,
'data' => ArticleModel::getArticles()
]; ];
echo $twig->render('vuephp1.html', [ echo $twig->render('listArticle.html', [
'dVue' => $dVue 'dVue' => $dVue
]); ]);
} }
@ -78,7 +78,7 @@ class Controleur
$dVue = [ $dVue = [
'nom' => $nom, 'nom' => $nom,
'age' => $age, 'age' => $age,
'data' => $data, //'data' => $data,
]; ];
echo $twig->render('vuephp1.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]); echo $twig->render('vuephp1.html', ['dVue' => $dVue, 'dVueEreur' => $dVueEreur]);

@ -1,5 +1,4 @@
<?php <?php
echo "hey";
//chargement config //chargement config
require_once __DIR__ . '/config/config.php'; require_once __DIR__ . '/config/config.php';

@ -4,14 +4,12 @@ namespace model;
use DAL\{AdminGateway, ArticleGateway, Connection}; use DAL\{AdminGateway, ArticleGateway, Connection};
use metier; use metier;
require ('../DAL/ArticleGateway.php');
require ('../DAL/Connection.php');
class ArticleModel class ArticleModel
{ {
public static function getArticles() : array public static function getArticles() : array
{ {
$gwArticle = new ArticleGateway(new Connection('mysql:host= londres.uca.local ; dbname= dbrorossetto', 'rorossetto', 'tpphp')); $gwArticle = new ArticleGateway(new Connection('mysql:host=londres.uca.local ; dbname=dbrorossetto', 'rorossetto', 'tpphp'));
$tabArticle = array(); $tabArticle = array();
$res = $gwArticle->getAllArticles(); $res = $gwArticle->getAllArticles();
foreach($res as $row){ foreach($res as $row){

@ -49,6 +49,9 @@ class Parser
} }
/**
* @throws Exception
*/
public function parseAll($fluxes){ public function parseAll($fluxes){
foreach ($fluxes as $flux){ foreach ($fluxes as $flux){
$tabArticles[] =$this->parseArticles($flux); $tabArticles[] =$this->parseArticles($flux);
@ -56,6 +59,9 @@ class Parser
return $tabArticles; return $tabArticles;
} }
/**
* @throws Exception
*/
public function addAllArticles(){ public function addAllArticles(){
$allFlux = $this->fluxGateway->findAllFlux(); $allFlux = $this->fluxGateway->findAllFlux();

Loading…
Cancel
Save