你在找empty
,你可以把这个作为第三个参数传递给$this->Form->select()
。
array('empty' => array(0 => '-- Select --'))
文档
在此处查看文档:http: //book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
/**
* Method Signature
*
* public function select($fieldName, $options = array(), $attributes = array())
*
* ### 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.
*
*/
PHP:
// Example..
$this->Form->select(
'model', // First param = fieldName
$options, // Second param = options
array('empty' => array(0 => '-- Select --')) // Third param = attributes
);
HTML:(渲染)
// Renders
<select>
<option value="0">-- Select --</option>
</select>
如果您不需要选项中的值,则可以删除键并只传递一个字符串值。