title: How to set and return virtual attribute value got from request in Yii
body: <p>I have a virtual public attribute in <code>ActiveRecord</code> class. When I receive <code>JSON</code> <code>RawBody</code> in <code>ActiveController</code> class I am trying to assign parsed JSON to <code>$model-&gt;attributes</code>. Request JSON looks like:</p>
  
  <pre><code>{
    "name": "test",
    "address": "a place on earth",
    "_id": 1
  } 
  </code></pre>
  
  <p>Now in the above JSON <code>_id</code> is the key which I have declared as a <code>public $_id;</code> in <code>ActiveRecord</code> class also I have used setter getter for this property like this:</p>
  
  <pre><code>public function setId ($value) 
  {
      $this-&gt;_id = $value;
  }
  
  public function getId ($value)
  {
      return $this-&gt;_id;
  }
  </code></pre>
  
  <p>ActiveController methods:</p>
  
  <pre><code>public function actionPush() 
  {
      $data = $this-&gt;getRequestData();
      $model = new User();
      $model-&gt;attributes = $data;
  
      if($model-&gt;save())
          return ['status' =&gt; 200, 'message' =&gt; 'Record added successfully', 'record' =&gt; $model];
  
      return ['status' =&gt; 400, 'message' =&gt; 'Records not updated', 'errors' =&gt; $errors];
  }
  
  public function getRequestData()
  {
      $body = \Yii::$app-&gt;request-&gt;getRawBody();
  
      $parser = new JsonParser();
  
      return $parser-&gt;parse($body, 'application/json');
  }
  </code></pre>
  
  <p>Now I want response like this:</p>
  
  <pre><code>{
      "status": 200,
      "message": "Record added successfully",
      "record": {
              "id": 10,
              "name": "test",
              "_id": 1
          }
  }
  </code></pre>
  
  <p>But getting like this:</p>
  
  <pre><code>{
      "status": 200,
      "message": "Record added successfully",
      "record": {
              "id": 10,
              "name": "test"
          }
  }
  </code></pre>
  
  <p>How do I achieve the result? </p>