Bonjour ,
je suis débutant en dev PHP avec la methode MVC .
J'ai une application qui affiche les plats, et les utilisateurs doivent passer des commandes,...
J'ai une page qui recupere les commande et affiche les resultant comme suit :
je voudrais , si l'utilisateur clique sur le bouton continuer , avoir un une autre page qui affichera la somme totale des plats commandés, le prix total a payer ainsi qu'un bouton de suppression d'un des produit ajouté dans le panier.
Je ne sais ^pas comment faire.
voici la vue qui affiche la capture d'ecran en haut:
puis le controleur correspondant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 <div class="container"> <div class="row"> <form method="POST" action="<?= url('Panier/index') ?>"> <table> <thead> <tr> <th data-field="id" class="white-text text-darken-2"> Plats</th> <th data-field="name" class="white-text text-darken-2">Quantité </th> <th data-field="price" class="white-text text-darken-2">P.U</th> <th data-field="price" class="white-text text-darken-2">Total</th> </tr> </thead> <tbody> <?php if (isset($_POST['plats'])){ ?> <?php foreach ($plats as $plat) { ?> <tr> <td><img src="webroot/img/Restaurant/<?= $plat->getIdP() ?>.jpg" height=35> <span class="white-text text-darken-2"><?= $plat->getNomP() ?></span></td> <td><span class="white-text text-darken-2"><?= $plat->amount?></span></td> <td><span class="white-text text-darken-2"><?= number_format($plat->getPrixCli(),2,',','') ?></span></td> <td><span class="white-text text-darken-2"><?= number_format($plat->getPrixCli()*$plat->amount,2,',','') ?></span></td> <?php // $a = array(2, 4, 6, 8); //echo "sum(a) = " . array_sum($a) . "\n"; ?> <?php } } ?> </tr> </tbody> <thead> </thead> </table> <div class="fixed-action-btn"> <button type="submit" class="btn btn-large btn-block green waves-effect"><span class="style1">Continuer</span></button> </div> </form> </div> </div>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 ?php require_once ROOT . DS . 'app' . DS . 'Controller' . DS . 'Controller.php'; require_once ROOT . DS . 'app' . DS . 'Model' . DS . 'RestaurantDAO.php'; require_once ROOT . DS . 'app' . DS . 'Model' . DS . 'PlatDAO.php'; class CommandeController extends Controller { public function index() { //debug ($_POST); $platDAO = new PlatDAO(); $plats = array(); if(isset($_POST['plats'])) { foreach ($_POST['plats'] as $k => $idP) { $plat = $platDAO->getByIdP($idP); $plat->amount = $_POST['amount'][$k]; $plats[] = $plat; //envoyer les valeurs a la vue $this->set(array("plats" => $plats)); }; } } }
Partager