CakePHP - populating select form

后端 未结 2 744
Happy的楠姐
Happy的楠姐 2021-02-11 11:03

I\'m trying to populate a drop down select form with values from a database.

Here is what I have currently.

$modes = Set::combine($this->Setting->         


        
2条回答
  •  清酒与你
    2021-02-11 11:42

    See http://book.cakephp.org/view/1022/find-list and http://book.cakephp.org/view/1062/displayField.

    $settings = $this->Setting->find('list', array(
        'conditions' => array('Setting.setting_name LIKE' => 'mode_%'),
        'fields'     => array('Setting.id', 'Setting.title')
    ));
    $this->set(compact('settings'));
    
    // view
    echo $this->Form->input('current_mode', array(
        'type'    => 'select',
        'options' => $settings,
        'empty'   => false
    ));
    

提交回复
热议问题