0

i have 3 reservations . each reservation have 3 biens. but it show me just one line. what can i do to show all the 3 line

    public function index_hote() {
    $this->Reservation->recursive = 1;
    $this->loadModel("BiensPersonne");
   if($this->Session->read('Auth.User.0.Personne.id')){
        $options = $this->BiensPersonne->findByPersonneId($this->Session-  >read('Auth.User.0.Personne.id')); 
   $this->loadModel("Personne");
   $biens=$this->Personne->findById( $options['BiensPersonne']  ['personne_id']);
    foreach ($biens['Bien'] as $bien) {
     $reservations=$this->Reservation-  >find('all',array('conditions'=>array('Reservation.idBien'=> $bien['idBien'])));
$this->paginate('Reservation');
$this->set('reservations', $reservations);
}}}

in the view

   <?php foreach ($reservations as $reservation): ?>
    <tr>
    <td><?php echo h($reservation['Reservation']['dateReserDu']); ?></td>
    <td><?php echo h($reservation['Reservation']['dateReserAu']); ?></td>                
     </tr>
   <?php endforeach ?>

when i do Debugger::dump($reservations[0]); it show me

 array(
'Reservation' => array(
    'idReser' => '1',
    'dateReserDu' => '2016-04-23',
    'dateReserAu' => '2016-04-27',
    'montantAPaye' => '500',
    'etatReservation' => 'attente',
    'iddev' => '0',
    'idBien' => '9',
    'id' => '24'
),
'Personne' => array(
    'login' => '*****',
    'id' => '24',
    'designation' => 'client',
    'nom' => 'mohamed',
    'prenom' => 'jmaa',
    'dateNaiss' => '1991-07-22',
    'adresse' => 'rue paris',
    'telFixe' => '26119945',
    'telMobile1' => '95632114',
    'telMobile2' => '98745213',
    'email' => 'wahibaml@gmail.com',
    'mdp' => '26111991',
    'lienPhotoPersonnel' => 'sou.jpg',
    'idVille' => '14'
),
'Device' => array(
    'iddev' => null,
    'nomdev' => null,
    'logodev' => null,
    'coefficient' => null
),
'Bien' => array(
    'idBien' => '9',
    'designBien' => 'maison pour couple',
    'aPropos' => 'grand maison',
    'capaciteAccueil' => '5',
    'nbSalleBain' => '1',
    'nbChambre' => '3',
    'nbLits' => '5',
    'description' => 'hhhhhhhhhhhhhhhhhhhhhhhhhh',
    'adresse' => 'rue ladikiya',
    'immeuble' => 'zitouna',
    'affichable' => false,
    'affichablePageAccueil' => false,
    'idtypelogement' => '1',
    'idVille' => '1',
    'idPays' => '1',
    'idTypeBien' => '1',
    'posLat' => '36.4236',
    'posLong' => '10.6088'
    )
  )

  array(
'Reservation' => array(
    'idReser' => '3',
    'dateReserDu' => '2016-04-08',
    'dateReserAu' => '2016-04-29',
    'montantAPaye' => '700',
    'etatReservation' => 'attente',
    'iddev' => '0',
    'idBien' => '21',
    'id' => '24'
),
'Personne' => array(
    'login' => '*****',
    'id' => '24',
    'designation' => 'client',
    'nom' => 'mohamed',
    'prenom' => 'jmaa',
    'dateNaiss' => '1991-07-22',
    'adresse' => 'rue paris',
    'telFixe' => '26119945',
    'telMobile1' => '95632114',
    'telMobile2' => '98745213',
    'email' => 'wahibaml@gmail.com',
    'mdp' => '26111991',
    'lienPhotoPersonnel' => 'sou.jpg',
    'idVille' => '14'
),
'Device' => array(
    'iddev' => null,
    'nomdev' => null,
    'logodev' => null,
    'coefficient' => null
),
'Bien' => array(
    'idBien' => '21',
    'designBien' => 'appartement à louer',
    'aPropos' => 'garnd appartement',
    'capaciteAccueil' => '5',
    'nbSalleBain' => '1',
    'nbChambre' => '4',
    'nbLits' => '5',
    'description' => 'garnd appartement',
    'adresse' => 'rue syrie',
    'immeuble' => 'zitouna',
    'affichable' => false,
    'affichablePageAccueil' => false,
    'idtypelogement' => '1',
    'idVille' => '2',
    'idPays' => '0',
    'idTypeBien' => '2',
    'posLat' => '0',
    'posLong' => '0'
     )
   )

 array(
'Reservation' => array(
    'idReser' => '2',
    'dateReserDu' => '2016-04-07',
    'dateReserAu' => '2016-04-20',
    'montantAPaye' => '500',
    'etatReservation' => 'attente',
    'iddev' => '0',
    'idBien' => '22',
    'id' => '24'
),
'Personne' => array(
    'login' => '*****',
    'id' => '24',
    'designation' => 'client',
    'nom' => 'mohamed',
    'prenom' => 'jmaa',
    'dateNaiss' => '1991-07-22',
    'adresse' => 'rue paris',
    'telFixe' => '26119945',
    'telMobile1' => '95632114',
    'telMobile2' => '98745213',
    'email' => 'wahibaml@gmail.com',
    'mdp' => '26111991',
    'lienPhotoPersonnel' => 'sou.jpg',
    'idVille' => '14'
),
'Device' => array(
    'iddev' => null,
    'nomdev' => null,
    'logodev' => null,
    'coefficient' => null
),
'Bien' => array(
    'idBien' => '22',
    'designBien' => 'appartement',
    'aPropos' => 'grand appartement',
    'capaciteAccueil' => '2',
    'nbSalleBain' => '1',
    'nbChambre' => '2',
    'nbLits' => '2',
    'description' => 'grand appartement',
    'adresse' => 'ruen marsa',
    'immeuble' => '',
    'affichable' => false,
    'affichablePageAccueil' => false,
    'idtypelogement' => '1',
    'idVille' => '1',
    'idPays' => '1',
    'idTypeBien' => '1',
    'posLat' => '0',
    'posLong' => '0'
)
 )

Plz what can i doo to show all the reservation that teirs idBien = Bien.idBien and i have many Biens. i use contain but it not work so i delete it in Bien Model

public $hasMany = array(
          'className' => 'Reservation',
        'foreignKey' => 'idBien',
        'conditions' => '',
        'fields' => '',
        'order' => ''
        ),

in Reservation Model

public $belongsTo = array(
    'Bien' => array(
        'className' => 'Bien',
        'foreignKey' => 'idBien',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);
wah
  • 17
  • 4
  • You ask same question again? Show us how you made relations between models. – Salines Apr 25 '16 at 13:57
  • in the Model Reservation :public $belongsTo = array( 'Bien' => array( 'className' => 'Bien', 'foreignKey' => 'idBien', 'conditions' => '', 'fields' => '', 'order' => '' ) ); in the model Bien :public $hasMany = array( 'Reservation' => array( 'className' => 'Reservation', 'foreignKey' => 'idBien', 'conditions' => '', 'fields' => '', 'order' => '' ), – wah Apr 25 '16 at 13:59
  • Not here, update your question, Reservation Model has / belong .. – Salines Apr 25 '16 at 14:00
  • yeah i update my question – wah Apr 25 '16 at 14:05
  • You need to paginate registration? – Salines Apr 25 '16 at 14:06
  • how ? i write this $this->paginate('Reservation'); – wah Apr 25 '16 at 14:10
  • You wrote "i have 3 reservations . each reservation have 3 biens."; But your reservations model not have $hasMany relation to Bien model. – Salines Apr 25 '16 at 14:13
  • yeah each bien have a reservation – wah Apr 25 '16 at 14:21
  • first rename (backup) your reservations controller to _ReservationController.php, and try cake bake controller Reservations, after creating new controller tray to paginate index and debug results. If succes, then extend pagination options to fetch other Models data – Salines Apr 25 '16 at 14:31
  • Possible duplicate of [Cakephp foreach condition](http://stackoverflow.com/questions/36830885/cakephp-foreach-condition) – floriank Apr 25 '16 at 15:14

0 Answers0