### Attributes:
- showParents - If included in the array and set to true, an additional option element
will be added for the parent of each option group. You can set an option with the same name
and it's key will be used for the value of the option.
- multiple - show a multiple select box. If set to 'checkbox' multiple checkboxes will be
created instead.
- empty - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- escape - If true contents of options will be HTML entity encoded. Defaults to true.
- value The selected value of the input.
- class - When using multiple = checkbox the class name to apply to the divs. Defaults to 'checkbox'.
- disabled - Control the disabled attribute. When creating a select box, set to true to disable the
select box. When creating checkboxes, true will disable all checkboxes. You can also set disabled
to a list of values you want to disable when creating checkboxes.
### Using options
A simple array will create normal options:
$options = array(1 => 'one', 2 => 'two);
$this->Form->select('Model.field', $options));
While a nested options array will create optgroups with options inside them.
$options = array(
1 => 'bill',
'fred' => array(
2 => 'fred',
3 => 'fred jr.'
)
);
$this->Form->select('Model.field', $options);
In the above 2 => 'fred' will not generate an option element. You should enable the showParents
attribute to show the fred option.
If you have multiple options that need to have the same value attribute, you can
use an array of arrays to express this:
$options = array(
array('name' => 'United states', 'value' => 'USA'),
array('name' => 'USA', 'value' => 'USA'),
);
public select ( string $fieldName, array $options = [], array $attributes = [] ) : string | ||
$fieldName | string | Name attribute of the SELECT |
$options | array | Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element |
$attributes | array | The HTML attributes of the select element. |
return | string | Formatted SELECT element |