title: Step-by-step how to create a yii CModel
body: <p>I'm trying to create a Yii CModel class so I can view the data in a filtered, sorted grid.</p>
  
  <p>It shouldn't be too complicated but I can't for the life of me work out how to do this. I'm looking for a step-by-step instruction set of how to get it going but I can't find anything. :(</p>
  
  <p>I do not want to use a database backend, so I'm extending CModel.</p>
  
  <p>I've put some code below but I'm just not sure of what to do next. Where does the actual data go? It must go in an array or something?</p>
  
  <p>Any help would be great.</p>
  
  <p>I've put some code in below, if it helps. Here's my model:</p>
  
  <pre><code>class MyModel extends CModel{
      public $id,
             $attribute1,
             $attribute2,
             $attribute3;
  
      public function search(){
          $criteria = new CDbCriteria;
  
          $criteria-&gt;compare('id', $this-&gt;id);
          $criteria-&gt;compare('attribute1', $this-&gt;attribute1);
          $criteria-&gt;compare('attribute2', $this-&gt;attribute2);
          $criteria-&gt;compare('attribute3', $this-&gt;attribute3);
  
          return new CActiveDataProvider($this, array(
              'criteria' =&gt; $criteria,
          ));
      }
  
  public function attributeNames(){
          return array(
              'id',
              'attribute1',
              'attribute2',
              'attribute3',
          );
      }
  }
  </code></pre>
  
  <p>Here's my controller:</p>
  
  <pre><code>class MyController extends CController{
  
      public function actionIndex() {
          $model = new MyModel('search');
  
          $model-&gt;unsetAttributes();
  
          if (isset($_GET['MyModel'])){
              $model-&gt;setAttributes($_GET['MyModel']);
          }
  
          $this-&gt;render('index', array(
              'model' =&gt; $model,
          ));
  }
  </code></pre>
  
  <p>And here's my view:</p>
  
  <pre><code>$this-&gt;widget('bootstrap.widgets.TbGridView', array(
      'type'=&gt;'striped bordered condensed',
      'dataProvider'=&gt;$model-&gt;search(),
      'filter' =&gt; $model(),
      'columns'=&gt;array(
          'id',
          'attribute1',
          'attribute2',
          'attribute3',
      )
  ));
  </code></pre>