Common Cgridview Tasks

Last modified: 
Sunday, March 29th, 2015


Common tasks and adjustments when working with Yii's CGridView and CDbCriteria.

Limit Result Set Based on a Condition

The following addition to MyModel.php will present a searchable gridview which includes only items where = 1.

public function search() {

  $criteria=new CDbCriteria;

  $criteria->condition = 'active = 1';  

  return new CActiveDataProvider($this, array(
    'pagination' => array(
      'pageSize' => 50,

The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.