title: Yii upload a file using a model
body: <p>I am simply trying to upload a file using a model. I get the exception message in the current situation (see model/controller/view below):</p>
  
  <pre><code>CException
  MyFile and its behaviors do not have a method or closure named "save". 
  </code></pre>
  
  <p>If my model extends CActiveRecord instead of CFormModel there is an another Exception: </p>
  
  <pre><code>CDbException
  The table "MyFile" for active record class "MyFile" cannot be found in the database. 
  </code></pre>
  
  <p>What is my mistake? These are the files:</p>
  
  <p><strong>MODEL: MyFile.php</strong></p>
  
  <pre><code>class MyFile extends CFormModel {
      public $image;
      public function rules () {
          return array (
              array ('image', 'file', 'types' =&gt; 'gif, jpg, png'),
          );
      }
  }
  </code></pre>
  
  <p><strong>CONTROLLER: MyFileController.php</strong></p>
  
  <pre><code>class MyFileController extends CController {
      public function actionCreate() {
          $model = new MyFile;
  
          if(isset($_POST['MyFile'])) {
  
              $model-&gt;attributes=$_POST['MyFile'];
              $model-&gt;image=CUploadedFile::getInstance($model,'image');
              if($model-&gt;save()) {
                  $path = Yii::app()-&gt;runtimePath.'/temp/uploadDirectory/'.$model-&gt;image;
                  $model-&gt;image-&gt;saveAs($path);
              }
          }
          $this-&gt;render('create', array('model'=&gt;$model));
      }
  }
  </code></pre>
  
  <p><strong>VIEW: create.php</strong></p>
  
  <pre><code> &lt;h1&gt;File-Upload&lt;/h1&gt;
  
   &lt;?php
  
      echo CHtml::form('','post',array('enctype'=&gt;'multipart/form-data'));
      echo CHtml::activeFileField($model, 'image');
      echo CHtml::submitButton('abschicken', array('name' =&gt; 'submit'));
      echo CHtml::endForm();
  
   ?&gt;
  </code></pre>