2011-02-08 7 views
0

J'ai actuellement ceci:confondu avec Peupler Sélectionnez le champ

Hôtels Contrôleur

class HotelsController extends AppController { 

    var $name = 'Hotels'; 

    function admin_add() { 
     $this->set('hotel_categories', $this->Hotel->HotelCategory->find('list')); 

     if (! empty($this->data)) { 

      $this->data['Page']['title'] = $this->data['Hotel']['title']; 
      $this->data['Page']['layout'] = 'index'; 

      if ($this->Hotel->saveAll($this->data)) { 
       $this->Session->setFlash('Your hotel has been saved', 'flash_good'); 
       $this->redirect(array('action' => 'admin_add')); 
      } 
     } 
    } 

HotelCategory Modèle

class HotelCategory extends AppModel { 
    var $name = 'HotelCategory'; 

    var $hasAndBelongsToMany = array(
     'Hotel' => array(
      'className' => 'Hotel' 
     ) 
    ); 

Modèle Hôtel

class Hotel extends AppModel { 
    var $name = 'Hotel'; 
    var $hasAndBelongsToMany = array(
     'HotelCategory' => array(
      'className' => 'HotelCategory' 
     ) 
    ); 

Voir

<div id="main"> 
     <h2>Add Hotel</h2> 
     <?php echo $this->Session->flash();?> 
     <div> 
     <?php 
     debug($hotel_categories); 
     echo $this->Form->create('Hotel'); 
     echo $this->Form->input('Hotel.title'); 
     echo $this->Form->input('HotelCategory', array('options' => 'select', 'multiple' => 'checkbox')); 
     echo $this->Form->input('Hotel.body', array('rows' => '3')); 

     echo $this->Form->input('Page.meta_keywords'); 
     echo $this->Form->input('Page.meta_description'); 

     echo $this->Form->end('Save Hotel'); 
     ?> 
     </div> 
<!-- main ends --> 
</div> 

Je peux confirmer que quand je debug($hotel_categories); qu'il existe des valeurs. Le problème que j'ai est que le $this->Form->input('HotelCategory', array('options' => 'select', 'multiple' => 'checkbox')) ne produit aucune option.

+0

figured it out. –

Répondre

2

Ce devrait être:

echo $this->Form->input('HotelCategory', array(
              'type' => 'select', 
              'multiple' => 'checkbox', 
              'options'=>$hotel_categories)); 
1

essayer définissant explicitement la liste des options dans la vue

<?php echo $this->Form->input('HotelCategory', array(
'type'=>'select', 
'options' => $hotel_categories, 
'multiple' => true)); ?>