1
<?php echo CHtml::dropDownList('Category', $model -> cate_id, CHtml::listData(Category::model() -> findAll(), 'id', 'name'), array('empty' => 'Select Category','submit'=>array('advert/loadAdvert','id'=>'5'))); ?>

我需要获取选定的下拉列表值,而不是硬编码 id,我必须为 id 放置该值。

public function actionloadAdvert($id) {
    $issueDataProvider = new CActiveDataProvider('Advert', array('criteria' => array('condition' => 'cate_id=:cate_id', 'params' => array(':cate_id' => $id), ), 'pagination' => array('pageSize' => 1, ), ));
    $this -> render('advertisement', array('model' => Advert::model(), 'issueDataProvider' => $issueDataProvider, ));
}

还有什么是学习yii的最佳书籍或资源。

4

1 回答 1

1
<?php
echo CHtml::dropDownList(
    'Category',
    $model->cate_id,
    CHtml::listData(Category::model()->findAll(), 'id', 'name'),
    array(
        'empty'    => 'Select Category',
        'onchange' => 'document.location.href = "/advert/loadAdvert/id/" + this.value',
    )
);
?>
于 2012-12-21T01:38:35.753 回答