Atelier développement web coté serveur
Compte rendu tp poo
Nom et prénom : zaibi fatma
Classe :dsi2.3
Ex1:
<?php
class Ville {
public $nom;
public $gouvernorat;
public function affiche() {
return "La ville " . $this->nom . " est dans le gouvernorat " .
$this->gouvernorat;
}
}
$ville1 = new Ville();
$ville1->nom = "moknine";
$ville1->gouvernorat = "monastir";
$ville2 = new Ville();
$ville2->nom = "cité riadh";
$ville2->gouvernorat = "Sousse";
echo $ville1->affiche();
echo "<br>";
echo $ville2->affiche();
?>
Ex2:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
class Ville {
public $nom;
public $gouvernorat;
public function __construct($n, $gouv) {
$this->nom = $n;
$this->gouvernorat = $gouv;
}
public function affiche() {
return "La ville " . $this->nom . " est dans le gouvernorat " .
$this->gouvernorat;
}
}
$ville1 = new Ville("moknine", "monastir");
$ville2 = new Ville("cité riadh", "sousse");
echo $ville1->affiche();
echo "<br>";
echo $ville2->affiche();
?>
</body>
</html>
Ex3:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
class Personne {
private $nom;
private $prenom;
private $adresse;
public function __construct($n, $p, $adr) {
$this->nom = $n;
$this->prenom = $p;
$this->adresse = $adr;
}
public function __destruct() {
}
public function getpersonne() {
return "La personne de nom complet " . $this->nom . " " . $this-
>prenom . " a pour adresse " . $this->adresse;
}
public function setadresse($adresse) {
$this->adresse = $adresse;
}
}
$personne = new Personne("Fatma", "Zaibi", "Moknine");
$personne->setadresse("rue Farhat Hached");
echo $personne->getpersonne();
?>
</body>
</html>
Ex4:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
class Form {
private $formCode; // Contient le code HTML du formulaire
// Constructeur : initialise le formulaire avec les balises <form> et
<fieldset>
public function __construct($action, $method) {
$this->formCode = "<form action='$action' method='$method'>\n";
$this->formCode .= "<fieldset>\n";
}
// Méthode pour ajouter une zone de texte
public function setText($name, $label, $placeholder = "") {
$this->formCode .= "<label for='$name'>$label:</label>\n";
$this->formCode .= "<input type='text' id='$name' name='$name'
placeholder='$placeholder'>\n<br>\n";
}
// Méthode pour ajouter un bouton d'envoi
public function setSubmit($value) {
$this->formCode .= "<input type='submit' value='$value'>\n";
}
// Méthode pour terminer le formulaire et récupérer son code
public function getForm() {
$this->formCode .= "</fieldset>\n</form>\n";
return $this->formCode;
}
}
?>
</body>
</html>
Test :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
// Inclure le fichier contenant la classe Form
include 'ex4.php';
// Créer un objet Form
$form = new Form("submit.php", "post");
// Ajouter deux zones de texte
$form->setText("username", "Nom d'utilisateur", "Entrez votre nom");
$form->setText("email", "Email", "Entrez votre email");
// Ajouter un bouton d'envoi
$form->setSubmit("Envoyer");
// Afficher le formulaire
echo $form->getForm();
?>
</body>
</html>
Ex5 :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
require_once 'ex4.php';
class Form2 extends Form {
public function setRadio($name, $options) {
foreach ($options as $value => $label) {
$this->formcode .= "<label><input type=\"radio\" name=\"$name\"
value=\"$value\"> $label</label>\n";
}
}
public function setCheckbox($name, $options) {
foreach ($options as $value => $label) {
$this->formcode.= "<label><input type=\"checkbox\"
name=\"{$name}[]\" value=\"$value\"> $label</label>\n";
}
}
}
?>
</body>
</html>
Test :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
require_once 'ex5.php';
$form2 = new Form2("submit.php", "POST");
$form2->setText("username", "Nom d'utilisateur", "", "Entrez votre nom");
$form2->setRadio("gender", ["M" => "Homme", "F" => "Femme"]);
$form2->setCheckbox("hobbies", ["sport" => "Sport", "music" => "Musique",
"travel" => "Voyage"]);
$form2->setSubmit("Valider");
echo $form2->getForm();
?>
</body>
</html>
Ex7 :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
public abstract class personne{
private $nom;
private $prenom;
public function __construct($nom,$prenom){
$this->nom=$nom;
$this->prenom=$prenom;
}
}
?>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
require_once 'personne.php';
public class client extends personne{
private $adresse;
public function __construct($adresse){
parent::__construct($nom, $prenom);
$this->adresse=$adresse;
}
public function setcoord(){
return "nom: $this->nom,prenom:$this->prenom,adresse:$this-
>adresse";
}
}
?>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
require_once 'personne.php';
public class électeur extends personne{
public $bureau_vote;
public $vote;
public électeur($nom,$prenom,$bureau_vote){
parent::__construct($nom,$prenom)
$this->bureau_vote=$bureau_vote;
$this->vote=false;
}
public function avoter(){
$this->vote=true;
}
public function getInfo() {
$statusVote = $this->vote ? "a voté" : "n'a pas voté";
return "Nom : $this->nom, Prénom : $this->prenom, Bureau de vote :
$this->bureau_de_vote, Statut : $statusVote";
}
}
?>
</body>
</html>