Html::dropDownList
时间: 2024-05-02 08:21:54 浏览: 140
Html::dropDownList is a method used in Yii framework to create a dropdown list in HTML. It is used to create a select element with options that a user can select from.
Syntax:
```php
Html::dropDownList($name, $selection = null, $items = [], $options = [])
```
Parameters:
- $name: string, the name attribute of the select element.
- $selection: mixed, the selected value(s). This can be a string or an array of strings depending on whether the select element is multiple or not.
- $items: array, the options for the select element. The keys are the option values and the values are the option labels.
- $options: array, the HTML attributes for the select element. This can include attributes like class, id, style, etc.
Example:
```php
echo Html::dropDownList('gender', null, ['M' => 'Male', 'F' => 'Female'], ['prompt' => 'Select Gender']);
```
This will create a dropdown list with name attribute "gender", no pre-selected value, two options "Male" and "Female" with values "M" and "F" respectively, and a prompt option "Select Gender".
阅读全文