Using Cgridview To List Certain Records Only

Hi folks, I am trying to use the CGridView widget to list only records with the same foreign key, namely to list all Enrollment Status records belonging to a single Student Record. The result would be the same as if I used the Search button in the admin page, and selected a single student. I’m trying to pass the student_record_id to the actionAdmin() method in the controller like so:


But in actionAdmin(), how do you pass this id to the search() function in the model?


Any help appreciated.

Larry Z.


$model->student_record_id =$id;

In Admin Action you need to do something like this

$model = new Model('search');

$model->id = 1; //Change it according to your need

And in Cgrid view you can access $model->search();

Hi list, the solution is really this easy:


$model->student_record_id =$id;

Thanks a million ezekielnoob, and codesutra.

Works perfectly.

After reading this article:

I see now that in the controller’s actionAdmin, $model is used only as a placeholder for the search parameters submitted by _search.php. If there are no parameters, the CActiveDataProvider returns all records.


Larry Z.