Bonsoir cher tous,
je manipule trois tables: Marchepublic, Bailleur et Marchefinancement qui sont liés selon le model:
Marchefinancement Model
a partir de la vue du Marché, on peut ajouter un financement (Marchefinancement);
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 <?php App::uses('AppModel', 'Model'); /** * Marchefinancement Model * * @property Marchepublic $Marchepublic * @property Bailleur $Bailleur */ class Marchefinancement extends AppModel { /** * Display field * * @var string */ public $displayField = 'id'; //The Associations below have been created with all possible keys, those that are not needed can be removed /** * belongsTo associations * * @var array */ public $belongsTo = array( 'Marchepublic' => array( 'className' => 'Marchepublic', 'foreignKey' => 'marchepublic_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'Bailleur' => array( 'className' => 'Bailleur', 'foreignKey' => 'bailleur_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); }
pour cela, j'ai recuperé l'id du marché depuis la vue
et je le gere dans la fonction add() de Marchefinancement:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <?php echo $this->Html->link("Financements", array('controller' => 'marchefinancements','action'=> 'add', $marchepublic['Marchepublic']['id']), array( 'class' => 'button')); ?>
sur la vue add des Marchefinancements, je veux ajouter de nouveaux financements et au fur et à mesure, s'affiche les lignes enregistrées sur la meme page.
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 public function add($id = null) { if ($this->request->is('post')) { $this->Marchefinancement->create(); if ($this->Marchefinancement->save($this->request->data)) { $this->Session->setFlash(__('The marchefinancement has been saved.')); //return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The marchefinancement could not be saved. Please, try again.')); } } $marchepublics = $this->Marchefinancement->Marchepublic->find('list',array( 'fields' => array('Marchepublic.objet'), 'conditions' => array('Marchepublic.id =' => $id), 'recursive' => 0 )); $montantmarche = $this->Marchefinancement->Marchepublic->find('list',array( 'fields' => array('Marchepublic.montant'), 'conditions' => array('Marchepublic.id =' => $id), 'recursive' => 0 )); $bailleurs = $this->Marchefinancement->Bailleur->find('list'); $this->set(compact('marchepublics', 'bailleurs', 'montantmarche')); $this->Paginator->settings = $this->paginate; $this->set('marchefinancements', $this->Marchefinancement->find('all',array( 'conditions' => array('Marchepublic.id' => $id), 'recursive' => 0 )) , $this->paginate()); }
jusque là tout va bien...
dans ma vue add:
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 <table cellpadding="0" cellspacing="0" border="0" class="responsive dynamicTable table table-bordered" width="100%" > <thead> <tr> <th>Bailleur</th> <th>Taux</th> <th>Montant Bailleur</th> </tr> </thead> <tbody > <?php foreach ($marchefinancements as $marchefinancement): ?> <tr> <td><?php echo h($marchefinancement['Marchefinancement']['bailleur_id']); ?> </td> <td><?php echo h($marchefinancement['Marchefinancement']['taux']); ?> </td> <td><?php echo h($marchefinancement['Marchefinancement']['montantbailleur']); ?> </td> </tr> </tbody> <?php endforeach; ?> </table> <?php echo debug($marchefinancement) ?> </div>
SEULEMENT....
les bailleurs n'affichent que leurs id, je voudrais faire ressortir le nom des bailleurs.
aidez-moi svp!!!
Partager