*/ $method = $_SERVER['REQUEST_METHOD']; /** * Application du verbe sur la ressource */ switch ($method) { case 'GET': if (isset($_GET['action']) && $_GET['action'] == "all") { try { getVilles(); } catch (Exception $e) { echo $e->getMessage(); } } else { try { getVille(); } catch (Exception $e) { echo $e->getMessage(); } } break; case 'DELETE': deleteVille(); break; case 'PUT': updateVille(); break; case 'POST': createVille(); break; default:
<?php if (isset($_POST['monNom']) && !empty($_POST['monNom'])) { echo getNom($_POST['monNom']); } if (isset($_POST['monCp']) && !empty($_POST['monCp'])) { echo getVille($_POST['monCp']); } function getNom($monNom) { $htmlMonNom = "Bonjour <span id='monNom'>{$monNom}</span>"; $reponse = ""; switch ($monNom) { case "Luigi": $reponse = ", je te connais tu es le frère de Mario"; break; case "Mario": $reponse = ", je te connais tu es le frère de Luigi"; break; case "Père noel": $reponse = ", Joyeux noël et bonne année"; break; default: $reponse = ", Désolée mais je ne te connais pas"; } return "<div id='bonjour'>{$htmlMonNom} {$reponse}</div>"; } function getVille($monCp) { header('Content-Type: application/json'); return trouverVilleIlleEtVilaine($monCp);