title: How to filter with Yii gridView?
body: <p>I'm totally lost with filtering in Yii gridView . I'm trying to do a filtering using CArrayDataProvider. I check all of the forums and they said that i have to used this extended class <strong>filtersform</strong>, but at the moment i'm stuck with this error: 
  <img src="https://i.stack.imgur.com/qeIf4.png" alt="enter image description here"></p>
  
  <p>Can someone help me with this ? to do a filtering using CArrayDataProvider and Yii grid</p>
  
  <p>This is my <strong>MODEL</strong>:</p>
  
  <pre><code>class Common extends ActiveRecord{
  
      private $connection_common; 
      private $connection_invetory;
  
      /**
       * @see db connections 
       */
      public function __construct(){
          $this-&gt;connection_common =  Yii::app()-&gt;dbcommon;
          $this-&gt;connection_invetory =  Yii::app()-&gt;db;
      }
  
      public static function model($className=__CLASS__){
          return parent::model($className);
      }
      public function getAllUsers(){
  
          $command = $this-&gt;connection_invetory-&gt;createCommand(" 
              SELECT id, `name`, active, username, `function`, email ,active FROM users order by id desc;
          ")-&gt;queryAll();
          $dataProvider = new CArrayDataProvider($command, array(
              'id'=&gt;'user',
              'sort'=&gt;array(
                  'defaultOrder'=&gt;'id DESC',
              ),
              'pagination'=&gt;array(
                  'pageSize'=&gt;15,
              ),
          ));
          return $dataProvider;
  
      }
  }
  </code></pre>
  
  <p>this is my <strong>CONTROLLER</strong>:</p>
  
  <pre><code> class MainController extends Controller {
          public function actionIndex() {
  
              $getApplicationNames = Common::model()-&gt;getApplications();
              $getAllRoleNames = Common::model()-&gt;getAllRoles();
  
              $getAllUsers = Common::model()-&gt;getAllUsers();
              $filtersForm = new FiltersForm;
              if (isset($_GET['FiltersForm'])) {
                  $filtersForm-&gt;filters = $_GET['FiltersForm'];
              }
              $resultData = $filtersForm-&gt;filter($getAllUsers);
  
              $this-&gt;render('index', array(
                  'users' =&gt; $getAllUsers,
                  'filtersForm' =&gt; $filtersForm
              ));
          }
      }
  </code></pre>
  
  <p>AND THIS IS MY <strong>VIEW</strong>: </p>
  
  <pre><code>$this-&gt;widget('GridView', array(
          'dataProvider' =&gt; $users,
          'id' =&gt; 'my_grid_view',
          //'filter' =&gt; $filtersForm,
          'itemsCssClass'=&gt;'table',
          'pager' =&gt; array(
                  'class'                 =&gt; 'CLinkPager',
                  'prevPageLabel'         =&gt; 'Previous',
                  'nextPageLabel'         =&gt; 'Next',
                  'header'                =&gt; '',
                  'previousPageCssClass'  =&gt; 'btn btn-info btn-sm',
                  'selectedPageCssClass'  =&gt; 'btn btn-warning btn-sm',
                  'internalPageCssClass'  =&gt; 'btn btn-info btn-sm',
                  'firstPageCssClass'     =&gt; 'btn btn-info btn-sm',
                  'nextPageCssClass'      =&gt; 'btn btn-info btn-sm',
          ),
          'columns' =&gt; array(
              array(
                  'name' =&gt; 'User ID',
                  'type' =&gt; 'raw',
                  'value' =&gt; 'CHtml::encode($data["id"])'
              ),
              array(
                  'name' =&gt; 'Username',
                  'type' =&gt; 'raw',
                  'value' =&gt; 'CHtml::encode($data["username"])'
              ),
              array(
                  'name' =&gt; 'Name',
                  'type' =&gt; 'raw',
                  'value' =&gt; 'CHtml::encode($data["name"])'
              ),
              array(
                  'name' =&gt; 'Email',
                  'type' =&gt; 'raw',
                  'value' =&gt; 'CHtml::encode($data["email"])'
              ),
              array(
                  'name' =&gt; 'Role',
                  'type' =&gt; 'raw',
                  'value' =&gt; 'CHtml::encode($data["function"])'
              ),
              array(
                  'name' =&gt; 'Status',
                  'type' =&gt; 'raw',
                  'value' =&gt; 'CHtml::encode($data["active"])'
              ),
              array(
                  'name'  =&gt; 'Action',
                  'type'  =&gt; 'raw',
                  'value' =&gt; 'CHtml::link("&lt;button  type=\'button\'  class= \'btn btn-info user_ajax\' data-toggle=\'modal\' data-target=\'#myModal\'&gt;Info&lt;/button&gt;")',
              ),
          ),  
  
      ));
  </code></pre>
  
  <p>and this is the <strong>Filtersform CLASS</strong> content , which is located in the model:</p>
  
  <p>
  
  <pre><code>/**
   * Override magic getter for filters
   */
  public function __get($name)
  {
      if(!array_key_exists($name, $this-&gt;filters))
          $this-&gt;filters[$name] = null;
      return $this-&gt;filters[$name];
  }
   public function rules()
   {
  return array(
          array('username', 'required'),
  );
  }
  /**
   * Filter input array by key value pairs
   * @param array $data rawData
   * @return array filtered data array
   */
  public function filter($data)
  {
      foreach($data AS $rowIndex =&gt; $row) {
          foreach($this-&gt;filters AS $key =&gt; $value) {
              // unset if filter is set, but doesn't match
              if(array_key_exists($key, $row) AND !empty($value)) {
                  if(stripos($row[$key], $value) === false)
                      unset($data[$rowIndex]);
              }
          }
      }
      return $data;
  }
  </code></pre>
  
  <p>}</p>