当yii中的下拉列表更改时,使用id调用操作

时间:2012-12-05 06:50:52

标签: php yii yii-components

<?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的最佳书籍或资源。

1 个答案:

答案 0 :(得分: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',
    )
);
?>