在模型生成的选择字段中添加空选项字段

时间:2011-09-03 16:34:01

标签: php cakephp

我的模特用户国家/地区 belongsTo 关系。所以当我添加

$this->Form->input('country');
例如, register.ctp 中的

会显示国家/地区的选择字段。

<select name="foo">
  <option value="germany">Germany</option>
  <option value="finland">Finland</option>
  <option value="usa">USA</option>
</select>

所以我的问题是:在选择区中首先获得一个空的选项字段是否存在问题?

像:

<select name="foo">
  <option value="0"></option>
  <option value="germany">Germany</option>
  <option value="finland">Finland</option>
  <option value="usa">USA</option>
</select>

2 个答案:

答案 0 :(得分:1)

$this->Form->input('country',array('empty'=>'No country'));

答案 1 :(得分:0)

试试这个......

$this->Form->input('country', array('empty'=>'Select a country'));
相关问题