Bonjour à tous !
J'ai un petit souci avec CakePhp (surement dû à ma mauvaise maîtrise du modèle MVC) et j'aurais besoin d'un conseil !
Alors je vais essayer de vous expliquer clairement !
J'ai une table événement dans ma BDD. J'ai une vue index.ctp qui affiche un tableau présentant chaque ligne de ma table.
Code index.ctp :
Voilà la partie qui me pose problème c'est la ligne : <td><?php echo $this->Html->link("Valider", array('action'=>'validatedemande',$v['id'])); ?></td>
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 <table class="table table-striped"> <tr> <th><?php echo $this->Paginator->sort('ref', 'Référence ticket'); ?></th> <th><?php echo $this->Paginator->sort('intervenant', 'Intervenant'); ?></th> <th>Actions</th> <th><?php echo $this->Paginator->sort('begindate', 'Date de début'); ?></th> <th><?php echo $this->Paginator->sort('tarif', 'Tarif (en euro)'); ?></th> </tr> <?php foreach($operations as $k=>$v): $v = current($v); ?> <tr> <td><?php echo $this->Html->link($v['ref'], array('action'=>'show',$v['id'])); ?></td> <td><?php echo $v['intervenant']; ?></td> <td><?php echo $this->Html->link("Valider", array('action'=>'validatedemande',$v['id'])); ?></td> <td><?php echo $v['begindate']; ?></td> <td><?php echo $v['tarif']; ?></td> </tr> <?php endforeach; ?> </table>
En fait ça me donne un lien qui envoie sur une autre vue pour pouvoir modifier la ligne en question.
Code validatedemande.ctp:
Voilà donc sur cette page j'ai juste un bouton valider et un bouton refuser. Sauf que c'est pas super pratique car pour chaque ligne, on doit cliquer sur le lien qui nous envoi sur l'autre page, valider ou refuser, puis cliquer sur le lien suivant, rechanger de page etc ...
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 <?php echo $this->Form->create('Post', array('class' => 'form-horizontal')); ?> <fieldset> <div class="control-group"> <?php echo $this->Form->input('id'); ?> </div> <div class="control-group"> <label for="label1" class="control-label"> </label> <?php echo '<div class="controls"><button id="label1" class="btn btn-success" name="data[Post][validate]" value=1 >Valider</button><button id="label2" class="btn btn-danger" name="data[Post][validate]" value=2 disabled>Refuser</button></div>'; ?> </div> </fieldset> <?php echo $this->Form->end(); ?>
Donc j'aimerais bien que le bouton valider et le bouton supprimer soit utilisable dans le tableau de la page index, comme ceci :
Code que j'aimerais pour index.ctp afin de ne plus avoir validatedemande.ctp :
J'ai juste mis l'html des 2 boutons direct dans les cases du tableau. mais mon souci c'est pour la sauvegarde dans le controller que ça passe pas !
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 <table class="table table-striped"> <tr> <th><?php echo $this->Paginator->sort('ref', 'Référence ticket'); ?></th> <th><?php echo $this->Paginator->sort('intervenant', 'Intervenant'); ?></th> <th>Actions</th> <th><?php echo $this->Paginator->sort('begindate', 'Date de début'); ?></th> <th><?php echo $this->Paginator->sort('tarif', 'Tarif (en euro)'); ?></th> </tr> <?php foreach($operations as $k=>$v): $v = current($v); ?> <tr> <td><?php echo $this->Html->link($v['ref'], array('action'=>'show',$v['id'])); ?></td> <td><?php echo $v['intervenant']; ?></td> <td><button id="label1" class="btn btn-success" name="data[Post][validate]" value=1 >Valider</button><button id="label2" class="btn btn-danger" name="data[Post][validate]" value=2 disabled>Refuser</button></td> <td><?php echo $v['begindate']; ?></td> <td><?php echo $v['tarif']; ?></td> </tr> <?php endforeach; ?> </table>
Voici mon controller associé à ces 2 vues :
Voilà ! J'ai essayé de faire un mix des 2 pour faire la sauvegarde dans index mais je n'y arrive pas ... Des conseils s'il vous plait ?
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 function index(){ $groupe = $this->Session->read('accessgroup'); if($groupe == '4' || $groupe == '5' || $groupe == '6'){ $this->paginate = array('Post' => array( 'limit' => 10, 'order' => array('Post.id' => 'desc')) ); }else{ $this->paginate = array('Post' => array( 'limit' => 10, 'order' => array('Post.id' => 'desc'), 'conditions' => array('Post.intervenant' => 'test')) ); } $d['operations'] = $this->Paginate('Post'); $this->set($d); } } function validatedemande($id = null){ if($this->request->is('put') || $this->request->is('post')){ if($this->Post->save($this->request->data)){ $this->Session->setFlash("L'opération a bien été modifiée","notif"); $this->redirect(array('action'=>'index')); } }elseif($id){ $this->Post->id = $id; $this->request->data = $this->Post->read(); } }
Partager