要在我的表单中创建一个选择的dafault值,我确实喜欢这样:
$def_volume = array(-1=>"Please select a volume");
$def_issue = array(-1=>"Please select issue");
$volumes = array_merge($def_volume,IssuePeer::getAllVolumesForListChoices());
$issues = array_merge($def_issue,IssuePeer::getAllIssuesForListChoices());
$this->setWidgets(array(
'keyword' => new sfWidgetFormInput(),
'volume' => new sfWidgetFormSelect(array('choices' => $volumes)),
'issue' => new sfWidgetFormSelect(array('choices' => $issues)),
));
$this->setValidators(array(
'keyword' => new sfValidatorString(array('required' => true)),
'volume' => new sfValidatorChoice(array('choices' => array_keys(IssuePeer::getAllVolumesForListChoices()))),
'issue' => new sfValidatorChoice(array('choices' => array_keys(IssuePeer::getAllIssuesForListChoices()))),
));
输出:
<select id="filterSearch_volume" name="filterSearch[volume]">
<option value="0">Please select a volume</option>
....
</select>
但我希望得到这样的输出:
<select id="filterSearch_volume" name="filterSearch[volume]">
<option value="">Please select a volume</option>
....
</select>
如果您注意第一个值的值是value="0"
,但我希望像value=""
一样返回“null”。
答案 0 :(得分:1)
你试过了吗?
$def_volume = array('' => "Please select a volume");
这似乎对我有用。
答案 1 :(得分:1)
$ this-&gt; widgetSchema ['employee_id'] - &gt; setOption('add_empty','请选择一名员工');