find finit dans TaskGateway

list-Gtw-Mdl
Nicolas FRANCO 2 years ago
parent 4ef8f2b12f
commit 7716d00a9a

@ -47,8 +47,19 @@ class TaskGateway
':id'=>array($id,PDO::PARAM_STR))); ':id'=>array($id,PDO::PARAM_STR)));
} }
# comment ça marche ? /*si on veut trouver une liste, juste chercher toutes les taches avec idList= id_de_la_liste*/
public function Find($element, $valeur){ public function Find($element, $valeur){
$query='SELECT * FROM Tache WHERE '.$element.'=:'.$element;
$this->con->executeQuery($query, array(
':'.$element =>array($valeur,PDO::PARAM_STR)));
$results=$this->con->getResults();
foreach($results as $row)
{
$tabTaches[]=new Task($row['id'],$row['titre'],$row['description'],$row['priorite'],
$row['idList'],$row['dateDebut'],$row['dateFin']);
}
return $tabTaches;
} }
} }
?> ?>

@ -3,10 +3,17 @@ require_once("../business/Task.php");
require_once("../dal/TaskGateway.php"); require_once("../dal/TaskGateway.php");
echo "<h1>2do test</h1>"; echo "<h1>2do test</h1>";
# nouvelle tache
$t = new Task(10,'testNico','laDescription','urgent','001'); $t = new Task(10,'testNico','laDescription','urgent','001');
//include("../dal/Connection.php");
# connection
include("credentials.php"); include("credentials.php");
$con = new Connection('mysql:host=localhost;dbname=phpproject',$user,$pass); $con = new Connection('mysql:host=localhost;dbname=phpproject',$user,$pass);
# gateway
$tgt = new TaskGateway($con); $tgt = new TaskGateway($con);
$tgt->insert($t); //$tgt->insert($t);
?> //$tgt->delete('10');
$tasks=$tgt->Find('idList','001');
foreach($tasks as $i)
echo $i->get_id().<\br>;

Loading…
Cancel
Save