title: Call to a member function saveAs() on a non-object in yii2
body: <p>I am trying to run an application in Yii2
  I tried to upload a user profile picture and it works greatly
  but the problem starts when I try to update the name file. It shows me an error like <code>Call to a member function saveAs() on a non-object</code>.
  I even tried to update without any changes.. even that time also show me the same error...
  but error goes if I change the pic.
  this is my controller</p>
  
  <pre><code>public function actionUpdate($id)
  {
      $model = $this-&gt;findModel($id);
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
  
          // get the instance of uploaded file
          $imageName = $model-&gt;user_username;
          $model-&gt;file = UploadedFile::getInstance($model,'user_avatar');
  
          $model-&gt;file-&gt;saveAs( '/uploads/'.$imageName.'.'.$model-&gt;file-&gt;extension );
  
          //save the path in DB..
          $model-&gt;user_avatar = 'uploads/'.$imageName.'.'.$model-&gt;file-&gt;extension;
          $model-&gt;save();
  
          return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;user_id]);
      } else {
          return $this-&gt;render('update', [
              'model' =&gt; $model,
          ]);
      }
  }
  </code></pre>
  
  <p>The model rules   </p>
  
  <pre><code>  public function rules()
              {
                  return [
  
                  [['user_email', 'user_password'], 'required'],
                      // [['user_password'], 'required'],
                      [['user_username'], 'string', 'max' =&gt; 45],
                      [['user_first_name'], 'required'],
                      [['user_app_user_id'], 'required',
                      [['user_type','user_app_name','user_status'], 'string'],
                      [['user_app_user_id'], 'integer'],
                      [['user_rememberMe'], 'boolean'],
                      [['user_first_name', 'user_last_name'], 'string', 'max' =&gt; 100],
                      [['user_email'], 'string', 'max' =&gt; 150],
                      [['user_password'], 'string', 'min'=&gt;6],
                      [['user_password'], 'string', 'max' =&gt; 40,
                      [['user_avatar'],'file'],
                      //[['user_avatar'], 'string', 'max' =&gt; 500],
                      [['user_verification_code','user_auth_key'], 'string'],
                      [['user_email'], 'email'],
                      [['user_email'], 'filter', 'filter' =&gt; 'trim'],
  
                      ];
              }
  </code></pre>