多くの苦労の後:
あなたがしなければならないことが2つあります。まず、サーバーからの変更されたデータが必要です。これは、モデルの検索機能を変更できるためです。これは、CListViewのデータプロバイダーを提供するものだからです。
したがって、モデルの関数で、データプロバイダーのを変更する条件をsearch()
追加できます。たとえば、次のようになります。if
$criteria
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
// added the following if condition to modify the criteria to include only videos of a certain category
if (isset($_GET['category']))
$criteria->compare('category',$_GET['category'],true);// my category is string, hence the third attribute
else
$criteria->compare('category',$this->category,true);// we need the else part, coz the search function is used for actual searching also, for instance in gridview filters/search
$criteria->compare('id',$this->id);
// your other attributes follow
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
注:比較する前に$_GET['category']をサニタイズすることが絶対に必要かどうかはわかりません。
次に、その関数を使用できるCListViewを更新する必要があります$.fn.yiiListView.update
。したがって、たとえば:
<div id="categoryupdating">
<?php
echo CHtml::dropDownList('dropit', '',
array('1'=>'Cateogry1','2'=>'Category2','3'=>'Category3','4'=>'Category4'),
array('onchange'=>"$.fn.yiiListView.update('videos', {url: '".Yii::app()->createUrl('controller/action')."?category='+$('#dropit option:selected').val()})"));
?>
</div>
ここではもちろん、おそらくなどの関数を使用してドロップダウンのデータを動的に入力するCHtml::listData
必要があり、コントローラー/アクションはCListViewのコントローラー/アクションである必要があります。
yiiのlistviewウィジェットのjavascript関数の詳細については、 jquery.yiilistview.jsファイルを確認してください。
注:$。fn.yiiListView.updateはid
、リストビューとurl
更新の呼び出しをパラメーターとして受け取ります。
編集:else
グリッドビューなどでの実際の検索に検索機能を使用するため、条件も追加しました。