title: Yii2 sendFile() - Trying to get property of non-object
body: <p>Hey guys I am trying to set a download button where a user can download a file, which is uploaded using kartik's File Input Widget(single upload).</p>
  
  <p>The codes resides inside the CRUD generated view/controllers/models.</p>
  
  <p>This is the view button code,</p>
  
  <pre><code>        &lt;?= Html::a('Download Uploaded File', ['download', 'id' =&gt; $model-&gt;form_id], [
      'class' =&gt; 'btn btn-danger',
      'data' =&gt; [
          'confirm' =&gt; 'Are you sure you want to download this item?',
          'method' =&gt; 'post',
      ],
  ]) ?&gt;
  </code></pre>
  
  <p>Controller function(Download),</p>
  
  <pre><code>public function actionDownload($id) {
      $model = $this-&gt;findModel($id);
  
     $path = Yii::getAlias('@web') . '/uploads';
     $file = '/borang/'.$model-&gt;form_id.'.'.$model-&gt;file-&gt;extension;
  
     if (file_exists($file)) {
  
     Yii::$app-&gt;response-&gt;sendFile($file);
  
    }
  }
  </code></pre>
  
  <p>Controller function(Upload which is inside the create action)</p>
  
  <pre><code>public function actionCreate()
      {   
  
          $model = new FormMovement();
  
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
  
              $model-&gt;file = UploadedFile::getInstance($model, 'file');
  
              if (!empty($model-&gt;file) &amp;&amp; $model-&gt;validate()) {
                      $model-&gt;fm_upload = 'uploads/borang/'.$model-&gt;form_id.'.'.$model-&gt;file-&gt;extension;
                      $model-&gt;save();
                      $model-&gt;file-&gt;saveAs('uploads/borang/'.$model-&gt;form_id.'.'.$model-&gt;file-&gt;extension);
                      return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;form_id]);
              }else{
                  $model-&gt;save();
                  return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;form_id]);
              }
  
          } else {
              return $this-&gt;render('create', [
                  'model' =&gt; $model,
              ]);
          }
      }
  </code></pre>
  
  <p>This is the error log,
  'Trying to get property of non-object' in C:\xampp\htdocs\adminsys\frontend\controllers\FormMovementController.php:181</p>
  
  <p>which points to,</p>
  
  <pre><code>$file = '/borang/'.$model-&gt;form_id.'.'.$model-&gt;file-&gt;extension;
  </code></pre>
  
  <p>inside the Download action(controller)</p>