Dropdown select list in CakePHP

前端 未结 10 952
一个人的身影
一个人的身影 2020-12-15 11:59

Does anybody know how to select the contents of one take from a different view in CakePHP?

I have a take itemgroups that has 2 fields ID an

相关标签:
10条回答
  • 2020-12-15 12:34

    Here is the code to display a select dropdown.

    <?php echo $form->input('inputname', array('type'=>'select', 'options'=>$cate, 'label'=>false, 'empty'=>'Category')); ?>
    

    where $cate is loaded with an array from a find('list') in the format

    array(0 => 'option1', 1=>'option2', etc etc etc

    0 讨论(0)
  • 2020-12-15 12:38

    You can use like this in your controller and view...

    //In Controller:
        $data=$this->Model->find('list',array('conditions'=>array()));
        $this->set('data',$data);
    
    //In View:
    
        echo $this->Form->select('field_name',$data,null,array("escape"=>false,"empty"=>"select"));
    

    If you want to show initially select value in dropdown then you can pass value where use null in above line.

    0 讨论(0)
  • 2020-12-15 12:44
    <?php 
        $arrCategory=array(1=>"Car",2=>"Boat",3=>"Bike");
        echo $form->input('inputname', array('options'=>$arrCategory, 'label'=>false,
                                      'empty'=>'Category','selected'=>'Your Value')); 
    ?>
    
    0 讨论(0)
  • 2020-12-15 12:45

    In controller:

    $Itemgroup = $this->Itemgroup->find('list',
      array(
        'fields' => array('ID','Description')
      )
    );
    
    $this->set('Itemgroup',$Itemgroup); 
    

    In View:

    $form->input('itemgroup_id', array('type' => 'select','options'=> $Itemgroup));
    
    0 讨论(0)
提交回复
热议问题