Bonjour,
j'ai une table 'Formation'. Pour chaque formation d'un enseignant on a une date début et une date fin.
Dans ma vue j'ai :
Les formations de l'enseignant s'affichent sans problème.
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 <script type="text/javascript"> $(function() { $.datepicker.setDefaults( $.datepicker.regional[ "" ] ); $("#datepicker").datepicker({ dateFormat: 'dd-mm-yy', altFormat: "d-m-y" }); $('#datepicker').datepicker({altField: '#altDate', altFormat: 'yy-mm-dd'}). datepicker('setDate', new Date(y, m-1, d)); }); </script> <?php echo $this->Form->create('Formation'); echo '<table width=100%>'; echo '<th width=5%>id</th><th width=5%>Code Etape</th><th width = "15%">Libellé formation</th><th width = "25%"> date ouverture</th><th width = "25%">date fermeture</th><th width = "1%">Hors délai</th><tr>'; $i=0; foreach ($formation as $formation) { echo '<tr><td>'.$formation['Formation']['id'].'</td>'; echo $this->Form->input('Formation.id',array('type'=>'hidden','value'=>$formation['Formation']['id'])); echo '<td >'.$formation['Formation']['code_etape'].'</td><td>'.$formation['Formation']['libelle'].'</td>'; echo '<td>'.$this->Form->input('Formation.date_ouverture',array('type'=>'text','label'=>false,'id'=>$formation['Formation']['id'].$i,'class'=>'datepicker', 'value' => $this->Time->format('d/m/Y',$formation['Formation']['date_ouverture']))).'</td>'; echo '<td>'.$this->Form->input('Formation.date_fin',array('type'=>'text','label'=>false,'id'=>$formation['Formation']['id'].$i+1,'class'=>'datepicker','value'=> $this->Time->format('d/m/Y',$formation['Formation']['date_fin']))).'</td>'; $horsDelai = array ('1'=>'Oui','0'=>'Non'); echo '<td>'.$this->Form->input('Formation.hors_delai',array('options'=>$horsDelai, 'value'=>$formation['Formation']['hors_delai'],'label'=>false)).'</td></tr>'; $i++; } echo '</table>'; echo $this->Form->end(__('Valider')); ?>
Dans le controller, j'ai :
Mon problème, il ne sauvegarde que le dernier enregistrement. Dans $this->request->data, je n'ai que la dernière formation du tableau . Pourquoi ? Comment faire si on a 3 formations et si on modifie les dates de la 1ere et de la 3ème pour tout sauvegarder.
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 <?php App::uses('AppController', 'Controller'); class FormationsController extends AppController { public $components = array('DebugKit.Toolbar'=>array('autoRun' => true),'RequestHandler','Session'); public $helpers = array('Js' => array('Jquery'),'Text','Time','Form','Session'); public $uses = array('Formation'); public function edit($enseig_id,$id = null) { $formation = $this->Formation->find('all', array( 'conditions'=>array ('enseignant_id'=>$enseig_id))); $this->set(compact('formation',$formation)); if ($this->request->is('post') || $this->request->is('put')) { foreach ($this->request->data['Formation'] as $formation) { $this->request->data['Formation']['date_ouverture'] = implode('-', array_reverse(explode('/', $this->request->data['Formation']['date_ouverture']))); $this->request->data['Formation']['date_fin'] = implode('-', array_reverse(explode('/', $this->request->data['Formation']['date_fin']))); if ($this->Formation->saveAll($this->request->data)) { $this->Session->setFlash('Les formations ont été enregistrées'); $this->redirect(array('controller'=>'memoires','action' => 'index')); } else { $this->Session->setFlash("Les formations n'ont pas été enregistrée", 'default', array('class' => 'message failure')); } } } } } ?>
J'ai essayé de mettre dans ma vue ce type de ligne pour chaque input
Mais ça ne fonctionne pas .... POURQUOI .?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 echo '<td>'.$this->Form->input( 'Formation.' . $i . 'date_ouverture', array( 'type'=>'text', 'label'=>false, 'id'=>$formation['Formation']['id'].$i, 'class'=>'datepicker', 'value' => $this->Time->format('d/m/Y',$formation['Formation']['date_ouverture']) ) ).'</td>';
Merci pour vos réponses
Pascale
Partager