如何将静态元素添加到yii dropDownList?

MEM*_*MEM 2 yii

echo $form->dropDownList(
              $model,'categoryId', 
                      CHtml::listData(Category::model()->findAllBySql(
                      'SELECT * from category where isnull(parent_id)'), 
                      'id', 'name'), 
                      array(
                            'empty'=>Yii::t('fim','Search All'),
                             Yii::t('fim','Jobs'), 
                             Yii::t('fim','Training'), 
                             Yii::t('fim','Events'), 
                             Yii::t('fim','News')
                      )
            );
Run Code Online (Sandbox Code Playgroud)

工作,培训,活动和新闻没有出现.

为了将这些值添加到选择框,我们如何/应该如何构建它?

谢谢

Jon*_*Jon 13

您无法使用$htmlOptions参数添加静态元素.我是这样做的:

$data = CHtml::listData(Category::model()->findAllBySql(
                        'SELECT * from category where isnull(parent_id)'), 
                        'id', 'name');
// Add extra options here: I am actually prepending with this syntax,
// but you are free to append or interleave instead. Array keys are the values.
$static = array(
    'jobs'     => Yii::t('fim','Jobs'), 
    'training' => Yii::t('fim','Training'), 
    'events'   => Yii::t('fim','Events'), 
    'news'     => Yii::t('fim','News'),
);

echo $form->dropDownList(
    $model,
    'categoryId',
    $static + $data,
    array('empty'=>Yii::t('fim','Search All')));
Run Code Online (Sandbox Code Playgroud)