我在cake php中使用该代码来创建下拉列表
<?php
$selected = 'Select';
$options = array('Select' => 'Select', 'New' => 'New', 'Used Dealer' => 'Used Dealer', 'Used Private' => 'Used Private');
echo $this->Form->select('car_type', $options, $selected);
?>
输出
select id="UsersCarType" name="data[Users][car_type]">
<option value=""></option>
<option selected="selected" value="Select">Select</option>
<option value="New">New</option>
<option value="Used Dealer">Used Dealer</option>
<option value="Used Private">Used Private</option>
</select>
我想删除此
<option value=""></option>
答案 0 :(得分:1)
默认为空白选项:
http://book.cakephp.org/1.3/view/1430/select
您可以传入$ attributes数组来修改该行为:
如果您希望显示自己的默认选项,请将您的字符串值添加到$ attributes变量中的'empty'键,或将其设置为false以关闭默认的空选项
所以,我假设这样做:
<?php
$selected = 'Select';
$options = array('Select' => 'Select', 'New' => 'New', 'Used Dealer' => 'Used Dealer', 'Used Private' => 'Used Private');
$attributes = array('empty' => false);
echo $this->Form->select('car_type', $options, $selected, $attributes);
?>