Search In View

How can I add a search in my _view file?

I have an account table, and the users are student and teacher. in the list or _view all record will be post right.

so I want to put a search field or dropdown on it. In dropdown there are two options teachers or students. If i choose the teacher only users/data of the teachers will be viewed.

thank you :)

Hi my friend

This code may be help you

$dataProvider=new CActiveDataProvider(‘Users’);

$this->widget(‘zii.widgets.grid.CGridView’, array(




 $this->widget('zii.widgets.grid.CGridView', array(



For more details

Dear Friend

I assumed that you want to do filter in CListView rather than in CGridView.

I also assumed that teacher and students belong to a column something like ‘designation’.


<?php echo CHtml::dropDownList("designation",'',array('teacher'=>"teacher","student"=>"student",),array("prompt"=>"select",'id'=>"designation"));?>

<?php $this->widget('zii.widgets.CListView', array(




)); ?>

<?php Yii::app()->clientScript->registerScript('account','




'); ?>

So in index.php I have added a drop down list. Based on the selection it is going to update the list by AJAX.

In controller

public function actionIndex()

{   $criteria=new CDbCriteria;

    if(isset($_GET['designation']) && $_GET['designation']!=="")


    $dataProvider=new CActiveDataProvider('Person',array(








thanks you konapaz and seenivasan for your help.

I used code the same as in the search filter, I based it there and it work.

Thanks both of you for your help ^^