cakephp - 在 cakephp 下拉菜单中添加默认选项 "Please Select"

标签 cakephp selection default-value

我是 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/

相关文章:

php - cakephp 3.0 元素可以有它的 Controller 吗?

algorithm - 如何在没有静态计数器的情况下模拟随机选择第 n 个访问者

visual-studio-2010 - VS "cascading style sheet version for validation"可以更改默认值吗?

qt - 如何阻止鼠标中键单击取消选择 QGraphicsScene 中的项目而不阻止它从场景中的项目?

grails - 在Grails Rich ui的dateChooser中设置默认时间

jquery - 重置jquery输入的默认值

cakephp - cakephp 中的税收百分比验证

javascript - cakephp javascript动态更新

php - Cakephp:无法将字符串偏移量用作数组

android:smoothScrollToPosition() 无法正常工作