简体   繁体   中英

Create a SelectBox using Form Helper in CakePHP3

I am trying to make a combo box for an edit page.

echo $this->Form->select('status', 
                        ['empty' => 'Select Status'], 
                        ['class' => 'form-control', 'required']
                    );

Here I want to add 2 things :

$options = array('0' => 'Inactive',
                 '1' => 'Active',
                );

and selected value. suppose that is $status;

I tried with different options but sometime it do not add classes and sometime it shows options in tag

It will be great if somebody give clue.

Thanks

<?= $this->Form->input('status', [
        'type' => 'select', 
        'options' => ['0' => __('Inactive') , '1' => __('Active')], 
        'empty' => __('Select Status'),
        'class' => 'form-control',
        'required' => true, 'label' => __('Type')
    ]) 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM