-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3665dcd
Showing
14 changed files
with
2,010 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Monde pokemon | ||
|
||
## Acquis | ||
|
||
- [ ] Capable d'installer une application PHP | ||
- [ ] Capable de faire fonctionner une application PHP sur un serveur local | ||
- [ ] Capable de composer du HTML sous forme de concaténations de chaînes PHP. | ||
- [ ] Capable de créer une classe PHP | ||
- [ ] Capable de créer une méthode statique | ||
- [ ] Capable de faire l'appel à une méthode statique | ||
|
||
## Préparation et prérequis | ||
|
||
1. Visual Studio Code | ||
1. WampServer ou XAMPP | ||
1. DB Browser for SQLite | ||
1. Compte Github | ||
|
||
## Étapes | ||
|
||
1. [Cloner](https://github.com/web3cstj) ou télécharger le dossier de départ du projet | ||
1. Ouvrir la base de données dans _DB Browser for SQLite_ et prendre note des noms des champs de la table `pokemons` | ||
1. S'assurer que le projet est bel et bien ouvert dans _VSCode_. | ||
1. Renommer les fichiers `index.html` et `details.html` qui se trouvent dans le dossier `public` pour qu'ils aient l'extension `.php`. | ||
1. Démarrerr le serveur dans le terminal de _VSCode_ : | ||
```bash | ||
php -S localhost:8000 -t public | ||
``` | ||
1. Tester dans le fureteur l'adresse `http://localhost:8000`. La page `index.php` devrait s'afficher. | ||
1. Créer un fichier `Pokemon.php` dans le dossier `app` et y ajouter la classe du même nom. | ||
```php | ||
//Pokemon.php | ||
<?php | ||
class Pokemon { | ||
} | ||
``` | ||
|
||
1. Dans la classe, créer les méthodes statiques `html_index` qui n'a pas de paramètres et `html_details` qui doit recevoir le paramètre `$id`. Les 2 méthodes retournent une chaîne de caractères. | ||
```php | ||
static public function html_index() { | ||
$resultat = ''; | ||
return $resultat; | ||
} | ||
static public function html_details($id) { | ||
$resultat = ''; | ||
return $resultat; | ||
} | ||
``` | ||
1. Mettre le HTML pertinent (provenant de `index.php` et `details.php`) dans chacune des méthodes et le transformer en PHP grâce à des concaténations successives. Exemple partiel : | ||
```php | ||
$resultat .= '<div class="perso">'; | ||
$resultat .= '<h1>Bulbizarre</h1>'; | ||
$resultat .= '<div><img src="https://www.pokebip.com/pokedex-images/artworks/1.png" alt="Bulbizarre"></div>'; | ||
return $resultat; | ||
``` | ||
1. Dans les pages `index.php` et `details.php`, faire l'inclusion de fichier `autoload.php` | ||
```php | ||
<?php | ||
include("../autoload.php"); | ||
?><!DOCTYPE html> | ||
... | ||
``` | ||
1. Supprimer respectivement les balises (et leur contenu) `div.liste` et `div.details` | ||
1. Tester les pages. Elles devraient être presque vides. | ||
1. Ajouter les appels aux méthodes statiques crées pour remplacer le HTML enlevé : | ||
```php | ||
//index.php | ||
... | ||
<?php echo Pokemon::html_index(); ?> | ||
... | ||
``` | ||
```php | ||
//details.php | ||
... | ||
<?php echo Pokemon::html_details(1); ?> | ||
... | ||
``` | ||
1. Tester. Les pages devraient fonctionner, mais donner toujours le même résultat. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
class Pokemon { | ||
static public function html_index() { | ||
$resultat = ''; | ||
$pdo = new PDO("sqlite:../pokemon.sqlite"); | ||
$stmt = $pdo->prepare("SELECT id, nom_fr, numero FROM pokemons ORDER BY numero LIMIT 10"); | ||
$stmt->execute(); | ||
$resultat .= '<div class="liste">'; | ||
$resultat .= '<h1>Les Pokémons</h1>'; | ||
$resultat .= '<table border="1">'; | ||
$resultat .= '<thead>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>No</th>'; | ||
$resultat .= '<th>Icône</th>'; | ||
$resultat .= '<th>Nom français</th>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '</thead>'; | ||
$resultat .= '<tbody>'; | ||
while (($objPokemon = $stmt->fetchObject()) !== false) { | ||
$resultat .= '<tr>'; | ||
$resultat .= '<td>'.intval($objPokemon->numero).'</td>'; | ||
$resultat .= '<td><img src="https://pokestrat.io/images/badges/'.intval($objPokemon->numero).'.png" alt="'.$objPokemon->nom_fr.'" style="width:64px; height:64px;"/></td>'; | ||
$resultat .= '<td><a href="details.php?id='.$objPokemon->id.'">'.$objPokemon->nom_fr.'</a></td>'; | ||
$resultat .= '</tr>'; | ||
} | ||
$resultat .= '</tbody>'; | ||
$resultat .= '</table>'; | ||
$resultat .= '</div>'; | ||
return $resultat; | ||
} | ||
static public function html_details($id) { | ||
$pdo = new PDO("sqlite:../pokemon.sqlite"); | ||
$stmt = $pdo->prepare("SELECT id, numero, nom_fr, nom_en, type1, type2, talents, pv, attaque, defense, attaque_speciale, defense_speciale, vitesse FROM pokemons WHERE id=?"); | ||
$stmt->execute([$id]); | ||
$resultat = ''; | ||
if (($objPokemon = $stmt->fetchObject()) !== false) { | ||
$resultat .= '<div class="details">'; | ||
$resultat .= '<h1>'.$objPokemon->nom_fr.'</h1>'; | ||
$resultat .= '<div><img src="https://www.pokebip.com/pokedex-images/artworks/'.intval($objPokemon->numero).'.png" alt=""></div>'; | ||
$resultat .= '</div>'; | ||
$resultat .= '<table border="1">'; | ||
$resultat .= '<tbody>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Numéro</th>'; | ||
$resultat .= '<td>'.$objPokemon->numero.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Nom français</th>'; | ||
$resultat .= '<td>'.$objPokemon->nom_fr.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Nom anglais</th>'; | ||
$resultat .= '<td>'.$objPokemon->nom_en.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Type(s)</th>'; | ||
if ($objPokemon->type2) { | ||
$resultat .= '<td>'.$objPokemon->type1.'/'.$objPokemon->type2.'</td>'; | ||
} else { | ||
$resultat .= '<td>'.$objPokemon->type1.'</td>'; | ||
} | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Talents</th>'; | ||
$resultat .= '<td>'.$objPokemon->talents.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Points de vie</th>'; | ||
$resultat .= '<td>'.$objPokemon->pv.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Attaque</th>'; | ||
$resultat .= '<td>'.$objPokemon->attaque.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Défense</th>'; | ||
$resultat .= '<td>'.$objPokemon->defense.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Attaque spéciale</th>'; | ||
$resultat .= '<td>'.$objPokemon->attaque_speciale.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Défense spéciale</th>'; | ||
$resultat .= '<td>'.$objPokemon->defense_speciale.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '<tr>'; | ||
$resultat .= '<th>Vitesse</th>'; | ||
$resultat .= '<td>'.$objPokemon->vitesse.'</td>'; | ||
$resultat .= '</tr>'; | ||
$resultat .= '</tbody>'; | ||
$resultat .= '</table>'; | ||
} | ||
return $resultat; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
set_include_path(__DIR__."/app"); | ||
spl_autoload_register(); | ||
?> |
Oops, something went wrong.