<?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的最佳书籍或资源。
答案 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',
)
);
?>