Cakephp Foreach Condition hasmany

时间:2016-04-25 13:40:06

标签: cakephp foreach conditional-statements contain

我有3个预订。每个预订有3个biens。但它只显示一行。我该怎么做才能显示所有3行

    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);
}}}
视图中的

   <?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 ?>

当我做Debugger :: dump($ reservations [0]);  它告诉我

 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我能做些什么来展示所有预订,即idBien = Bien.idBien 我有很多Biens。 我使用包含,但它不起作用,所以我删除它 在比恩模型

public $hasMany = array(
          'className' => 'Reservation',
        'foreignKey' => 'idBien',
        'conditions' => '',
        'fields' => '',
        'order' => ''
        ),
预订模型中的

public $belongsTo = array(
    'Bien' => array(
        'className' => 'Bien',
        'foreignKey' => 'idBien',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);

0 个答案:

没有答案