我是 cakephp 的新手。我需要添加一个默认值
<option value="0">--Please Select--</option>
在我的以下选择字段中:
$attributes = array("empty"=>false,"Selected" => 'Select City',"id" => "location");
echo $form->select("gal_location_id", $gal_locations,null,$attributes);
我试着添加
$gal_locations[0] = "--Select City--";
$attributes = array("empty"=>false,"default" => 0,"id" => "location");
但位于列表底部的选项。添加默认选项的正确方法是什么?
最佳答案
您正在寻找“空”属性:
$this->Form->input('gal_location_id', array(
'type' => 'select',
'options' => $gal_locations,
'empty' => 'Select City', // <-- Shows as the first item and has no value
'id' => 'location'
));
关于cakephp - 在 cakephp 下拉菜单中添加默认选项 "Please Select",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21274713/