-1

为了在我的表单中设置一个默认值,我喜欢这样:

   $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",但我希望像这样返回“null” value=""

4

2 回答 2

1

$this->widgetSchema['employee_id']->setOption('add_empty', '请选择员工');

于 2013-08-26T04:13:11.823 回答
1

你有没有尝试过:

$def_volume = array('' => "Please select a volume");

这似乎对我有用。

于 2013-04-23T15:43:56.373 回答