actuellement je suis a l'étape ou je test mon code !
je pense que la meme erreur reviens a plusieurs endroit ... mais je ne sais pas ou ...
voici mes class :
<?php
/**
* Created by PhpStorm.
* User: Adeline
* Date: 16/02/2019
* Time: 00:33
*/
class Assurance {
protected $id;
protected $nom;
protected $codePostal;
protected $email;
protected $ville;
protected $telephone;
protected $pays;
protected $numAssurer;
protected $adresse1;
protected $adresse2;
public function __construct( array $array =[] )
{
$this->hydrate($array);
}
public function getId() {
return $this->id;
}
public function getNom() {
return $this->nom;
}
public function getCodePostal() {
return $this->codePostal;
}
public function getEmail() {
return $this->email;
}
public function getVille() {
return $this->ville;
}
public function getTelephone() {
return $this->telephone;
}
public function getPays() {
return $this->pays;
}
/**
* @return mixed
*/
public function getNumAssurer() {
return $this->numAssurer;
}
/**
* @return mixed
*/
public function getAdresse1() {
return $this->adresse1;
}
/**
* @return mixed
*/
public function getAdresse2() {
return $this->adresse2;
}
public function setId( $id ) {
echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
$id = (int) $id;
if ($id > 0)
{
$this->id = $id;
}
}
public function setNom( $nom ) {
if (strlen(trim($nom)) > 0)
//strlen = Calcule la taille d'une chaîne
// trim = Supprime les espaces (ou d'autres caractères) en début et fin de chaîne
{
if (strpos($nom,"#") !== false)
// strpos = Cherche la position de la première occurrence dans une chaîne
{
throw new Exception("Le nom ne peut pas avoir de caracteres speciaux");
}
if (preg_match("/[0-9]/", "$nom"))
// preg_match = sert ici pour les cfiffres
{
throw new Exception("Le nom ne peut pas avoir de chiffre");
}
else
{
//echo "la chaîne $nom est correcte";
$this->nom = $nom;
}
}
}
public function setCodePostal( $codePostal ) {
if (preg_match('/[0-9]{5}/',$codePostal))
{
$this->codePostal = $codePostal;
} else {
echo "<br/>Aucun résultat n'a été trouvé.";
}
}
public function setEmail( $email ) {
//1) si la chaine n'est pas vide
if (strlen(trim($email)) == 0) {
//erreur
throw new LengthException("Le mail est vide",100); //code 100 == mail vide
} else {
//pas d'erreur on continue
// if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// //mail validé
$this->email = $email;
// } else {
// //erreur à gérer
// throw new Exception("Le mail est invalide",101); //code 101 == mail invalide
// }
}
}
public function setVille( $ville ) {
if (strlen(trim($ville)) > 0)
{
$this->ville = $ville;
if (preg_match("/[0-9]/", "$ville"))
{
throw new Exception("La ville ne peut pas avoir de chiffre");
}
}else{
echo "la ville est obligatoire";
}
}
public function setTelephone( $telephone ) {
$this->telephone = $telephone;
}
public function setPays( $pays ) {
if (strlen(trim($pays)) > 0)
{
$this->pays = $pays;
if (preg_match("/[0-9]/", "$pays"))
{
throw new Exception("La ville ne peut pas avoir de chiffre");
}
}else{
echo "le pays est obligatoire";
}
}
/**
* @param mixed $numAssurer
*/
public function setNumAssurer( $numAssurer ) {
$this->numAssurer = $numAssurer;
}
/**
* @param mixed $adresse1
*/
public function setAdresse1( $adresse1 ) {
$this->adresse1 = $adresse1;
}
/**
* @param mixed $adresse2
*/
public function setAdresse2( $adresse2 ) {
$this->adresse2 = $adresse2;
}
protected function hydrate($array){
echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
foreach ($array as $key => $value) {
$methodName = 'set'.ucfirst($key);
if(method_exists($this, $methodName)){
$this->$methodName($value);
}
}
}
}
<?php
/**
* Created by PhpStorm.
* User: Adeline
* Date: 19/02/2019
* Time: 19:09
*/
class Assurance_habitation extends Assurance {
protected $id;
protected $assurance;
public function __construct( array $data =[] )
{
//appel du constructeur parent puisqu'on est h�rit� de ...
parent::__construct($data);
}
/**
* @return mixed
*/
public function getId() {
return $this->id;
}
/**
* @return mixed
*/
public function getAssurance() {
return $this->assurance;
}
/**
* @param mixed $id_habitation
*/
public function setId( $id ) {
echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
$id = (int) $id;
if ($id > 0)
{
$this->id_habitation = $id;
}
}
/**
* @param mixed $assurance
*/
public function setAssurance( $assurance ) {
$this->assurance = $assurance;
}
}
voici mes manager assurance :
<?php
class ManagerAssurance extends Manager{
public function __construct( $mode = 'prod' ) {
debug( '<br>[debug]Dans "' . __CLASS__ . "::" . __FUNCTION__ . '" [/debug]', true );
parent::__construct( $mode );
}
public function read( $id ) {
echo '<br>[debug]Dans "' . __FUNCTION__ . '" [/debug]';
$req = $this->db->prepare( 'SELECT * FROM assurance WHERE id =:id' );
$req->bindValue( 'id', $id, PDO::PARAM_INT );
$req->execute();
$array= $req->fetch();
$oAssurance = new assurance( $array );
return $oAssurance;
}
public function add( $data ) {
echo '<br>[debug]Dans "' . __FUNCTION__ . '" [/debug]';
//bloc try/catch pour g�rer les exceptions
//provenant de Employer
try {
$oAssurance = new assurance( $data );
} catch ( LengthException $lengthException ) {
//cas longueur == 0
throw new Exception( $lengthException->GetMessage(), $lengthException->GetCode() );
} catch ( Exception $exception ) {
//autre cas (mais pour nous invalide)
throw new Exception( $exception->GetMessage(), $exception->GetCode() );
}
$req = $this->db->prepare( 'INSERT INTO assurance (nom,codePostal,email,ville,telephone,pays,numAssurer,adresse1,adresse2) VALUES(:nom,:codePostal,:email,:ville,:telephone,:pays,:typeassurance,:numAssurer,:adresse1,:adresse2)' );
$req->bindValue( 'nom', $oAssurance->getNom(), PDO::PARAM_STR );
$req->bindValue( 'codePostal', $oAssurance->getCodePostal(), PDO::PARAM_STR );
$req->bindValue( 'email', $oAssurance->getEmail(), PDO::PARAM_STR );
$req->bindValue( 'ville', $oAssurance->getVille(), PDO::PARAM_STR );
$req->bindValue( 'telephone', $oAssurance->getTelephone(), PDO::PARAM_STR );
$req->bindValue( 'pays', $oAssurance->getPays(), PDO::PARAM_STR );
$req->bindValue( 'numAssurer', $oAssurance->getNumAssurer(), PDO::PARAM_STR );
$req->bindValue( 'adresse1', $oAssurance->getAdresse1(), PDO::PARAM_STR );
$req->bindValue( 'adresse2', $oAssurance->getAdresse2(), PDO::PARAM_STR );
$req->execute();
$id = $this->db->lastInsertId();
$oAssurance->setId( $id );
}
public function getAllAssurance() {
$stm = "SELECT * FROM assurance";
//Ceci:
// $stmt = $this->connexion->query($req);
// return $stmt;
//resum� par cela
return $this->db->query( $stm );
}
public function getAssurance( $id ) {
$stm = "SELECT * FROM assurance WHERE id=:id";
//preparation == protection des donn?es ? venir
$stmt = $this->db->prepare( $stm );
//liaison des marqueur :toto aux donnees
$stmt->bindValue( 'id', $id, PDO::PARAM_INT );
//execution de la requete sur le serveur SQL
$stmt->execute();
return $stmt;
}
public function update( $data ) {
echo '<pre>' . print_r( $data, true ) . '</pre>';
echo '<br>[debug]SESSION';
echo '<pre>' . print_r( $data, true ) . '</pre>';
$req = $this->db->prepare( 'UPDATE assurance SET nom=:nom,codePostal=:codePostal,email=:email,ville=:ville,telephone=:telephone,pays=:pays,numAssurer=:numAssurer,adresse1=:adresse1,adresse2=:adresse2 WHERE id =:id' );
$req->bindValue( 'id', $data->getId(), PDO::PARAM_INT );
$req->bindValue( 'nom', $data->getNom(), PDO::PARAM_STR );
$req->bindValue( 'codePostal', $data->getCodePostal(), PDO::PARAM_STR );
$req->bindValue( 'email', $data->getEmail(), PDO::PARAM_STR );
$req->bindValue( 'ville', $data->getVille(), PDO::PARAM_STR );
$req->bindValue( 'telephone', $data->getTelephone(), PDO::PARAM_STR );
$req->bindValue( 'pays', $data->getPays(), PDO::PARAM_STR );
$req->bindValue( 'numAssurer', $data->getNumAssurer(), PDO::PARAM_STR );
$req->bindValue( 'adresse1', $data->getAdresse1(), PDO::PARAM_STR );
$req->bindValue( 'adresse2', $data->getAdresse2(), PDO::PARAM_STR );
if ( ! $req->execute() ) {
echo "<br>[debug] Erreur";
}
}
public function delete( $id ) {
// =>voir getLivre(id) pour modele
$req = "DELETE FROM assurance WHERE id=:id";
$stmt = $this->db->prepare( $req );
$stmt->execute();
if ( $stmt->rowCount() == 1 ) {
echo '[debug]OK 1 ligne inseree';
} else {
echo 'Erreur insertion donnees';
}
}
}
<?php
/**
* Created by PhpStorm.
* User: Adeline
* Date: 21/02/2019
* Time: 14:29
*/
class ManagerAssurance_habitation extends ManagerAssurance {
public function __construct( $mode = 'prod' ) {
debug('<br>[debug]Dans "'.__CLASS__."::".__FUNCTION__.'" [/debug]',true);
parent::__construct( $mode );
}
public function read($id){
echo '<br>[debug]Dans "'.__FUNCTION__.'" [/debug]';
$req = $this->db->prepare('SELECT * FROM Assurance_habitation WHERE id =:id');
$req->bindValue('id', $id, PDO::PARAM_INT);
$req->execute();
$array = $req->fetch();
$oAssurance_habitation = new assurance_habitation($array);
return $oAssurance_habitation;
}
public function add( $data ) {
echo '<br>[debug]Dans "' . __FUNCTION__ . '" [/debug]';
//bloc try/catch pour g�rer les exceptions
//provenant de Employer
try {
$oAssurance_habitation = new assurance_habitation( $data );
} catch ( LengthException $lengthException ) {
//cas longueur == 0
throw new Exception( $lengthException->GetMessage(), $lengthException->GetCode() );
} catch ( Exception $exception ) {
//autre cas (mais pour nous invalide)
throw new Exception( $exception->GetMessage(), $exception->GetCode() );
}
$req = $this->db->prepare( 'INSERT INTO Assurance_habitation (assurance) VALUES(:assurance)' );
$req->bindValue('numAssurer', $oAssurance_habitation->getAssurance(), PDO::PARAM_INT );
$req->execute();
$id = $this->db->lastInsertId();
$oAssurance_habitation->setId( $id );
}
public function getAllHabitation() {
$stm = "SELECT * FROM assurance_habitation";
//Ceci:
// $stmt = $this->connexion->query($req);
// return $stmt;
//resum� par cela
return $this->db->query($stm);
}
public function getHabitation($id) {
$stm = "SELECT * FROM assurance_habitation WHERE id=:id";
//preparation == protection des donn?es ? venir
$stmt = $this->db->prepare($stm);
//liaison des marqueur :toto aux donnees
$stmt->bindValue('id',$id,PDO::PARAM_INT);
//execution de la requete sur le serveur SQL
$stmt->execute();
return $stmt;
}
public function update($data){
echo '<pre>'.print_r($data,true).'</pre>';
echo '<br>[debug]SESSION';
echo '<pre>'.print_r($data,true).'</pre>';
$req = $this->db->prepare('UPDATE assurance_habitation SET assurance=:assurance WHERE id=:id');
$req->bindValue('id', $data->getId(), PDO::PARAM_INT);
$req->bindValue('assurance', $data->getAssurance(), PDO::PARAM_INT );
if (! $req->execute()) {
echo "<br>[debug] Erreur";
}
}
public function delete($id) {
// =>voir getLivre(id) pour modele
$req = "DELETE FROM assurance_habitation WHERE id=:id";
$stmt = $this->db->prepare($req);
$stmt->execute();
if ($stmt->rowCount() == 1) {
echo '[debug]OK 1 ligne inseree';
} else {
echo 'Erreur insertion donnees';
}
}
}
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Merci à tous. Vous pouvez me retrouver ici :
🌐 Visitez mon profil sur Comeup
🚀 Découvrez BeFreelancr
📱 Retrouvez-moi sur LinkedIn
Merci à tous. Vous pouvez me retrouver ici :
🌐 Visitez mon profil sur Comeup
🚀 Découvrez BeFreelancr
📱 Retrouvez-moi sur LinkedIn