passage de paramètres variables par URL

Par tilk2010, il y a 14 ans


slt je développe mon projet de fin d'étude et je voudrai savoir comment faire pour passer une variable par url comme l'exemple qui suit :

<a href="index.php?p=client&option=form_add_client">Ajout d'un client | </a>
<a href="index.php?p=client&option=liste_client">Liste Clients</a>

sachant que j'ai créer une classe client qui contient une fonction "form_add_client()" design du formulaire et une fonction "add_client()" contenant la requete insert (je travaille avec PDO)

je veux que quand je clique sur le lien 1 j'affiche le form de la fonction form_add_client et executer la requete et quand je clique sur le lien 2 afficher la liste des client

comment faire ? (c'est urgent je prépare mon PFE) merci

6 réponses

djtec, il y a 14 ans

Et ben tu récupère le paramètre avec un $_GET"option"] et suivant ce qu'il contient tu lance telle ou telle fonction.

Exemple:

$opt = $_GET"option"];
if($opt == 'form_add_client') {
    // ta fonction form_add_client
} else if($opt == 'liste_client') {
    // ta fonction liste_client
}
tilk2010, il y a 14 ans

je le met dans ma classe ou dans l'index ??

djtec, il y a 14 ans

dans l'index car c'est de la que tu instancie ta class et que tu envoie tes fonctions

tilk2010, il y a 14 ans

le message suivant est apparue :
Undefined index: option in C:\Program Files (x86)\EasyPHP-5.3.9\www\PFE\index.php on line 40
car option c'est le nom d'un champ caché qui se trouve dans un la classe client dans le fichier class.php

djtec, il y a 14 ans

Si dans ton url tu as index.php?p=client&option=form_add_client ceci devrait fonctionner.

if(isset($_GET"option"])) {
    $opt = $_GET"option"];

    if($opt == 'form_add_client') {
        // ta fonction form_add_client
    } else if($opt == 'liste_client') {
        // ta fonction liste_client
    }    
}
tilk2010, il y a 14 ans

ca marche à merveille merci beaucoup pour votre aide :)