title: How to fix mongodb array cannot be displayed, private by yii2 BaseActiveRecord?
body: <p>I tried to create table to display data value from the database document, but somehow it cannot be displayed. </p>
  
  <p>After several trouble solving, I found that my array was private by baseactiverecord even though I didn't use baseactiverecord on my models</p>
  
  <p>here my database User document</p>
  
  <pre><code>/* 1 */
  {
      "_id" : ObjectId("5c3da89284274926934b86a3"),
      "id" : 1,
      "username" : "admin",
      "password" : "admin",
      "role" : 20
  }
  
  /* 2 */
  {
      "_id" : ObjectId("5c3da90384274926934b86b1"),
      "id" : 2,
      "username" : "admin2",
      "password" : "admin2",
      "role" : 20
  }
  
  /* 3 */
  {
      "_id" : ObjectId("5c3da90384274926934b86b3"),
      "id" : 3,
      "username" : "admin3",
      "password" : "admin3",
      "role" : 20
  }
  
  /* 4 */
  {
      "_id" : ObjectId("5c3da90384274926934b86b5"),
      "id" : 4,
      "username" : "user",
      "password" : "user",
      "role" : 10
  }
  
  /* 5 */
  {
      "_id" : ObjectId("5c3da90384274926934b86b7"),
      "id" : 5,
      "username" : "user2",
      "password" : "user2",
      "role" : 10
  }
  </code></pre>
  
  <p>Models/User</p>
  
  <pre><code>&lt;?php 
  namespace home\models; 
  
  use Yii;
  use yii\base\Model;
  use yii\mongodb\Database;
  use yii\mongodb\Collection;
  use yii\mongodb\ActiveRecord;
  use yii\mongodb\Query;
  
  class User extends ActiveRecord {
    public $_id;
    public $id;
    public $username;
    public $password;
    public $role;
  
      public static function collectionName()
      { return 'User'; }
  
      public function attributes()
      {
        return [
           '_id',
           'id',
           'username',
           'password',
           'role',        
        ];
      }
  
  
  }
  ?&gt;
  </code></pre>
  
  <p>Controller/home</p>
  
  <pre><code>&lt;?php
  namespace home\controllers;
  
  use Yii;
  use yii\base\InvalidArgumentException;
  use yii\web\BadRequestHttpException;
  use yii\web\Controller;
  use yii\web\Response;
  use yii\helpers\Html;
  use yii\helpers\Url;
  use yii\filters\VerbFilter;
  use yii\filters\AccessControl;
  use home\models\ContactForm;    
  use home\models\LoginForm;   
  use home\models\SignupForm;        
  use home\models\User; 
  
  
  class HomeController extends Controller{
  
      public $layout = 'home';
      public function actionAbout()
      {
      $user = User::find()-&gt; all();
      return $this-&gt;render('about', ['model' =&gt; $user]); 
      }
  
  }
  </code></pre>
  
  <p>And this the result i got</p>
  
  <pre><code>Array
  (
      [0] =&gt; home\models\User Object
          (
              [_id] =&gt; 
              [id] =&gt; 
              [username] =&gt; 
              [password] =&gt; 
              [role] =&gt; 
              [_attributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da89284274926934b86a3
                          )
  
                      [id] =&gt; 1
                      [username] =&gt; admin
                      [password] =&gt; admin
                      [role] =&gt; 20
                  )
  
              [_oldAttributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da89284274926934b86a3
                          )
  
                      [id] =&gt; 1
                      [username] =&gt; admin
                      [password] =&gt; admin
                      [role] =&gt; 20
                  )
  
              [_related:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_relationsDependencies:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_errors:yii\base\Model:private] =&gt; 
              [_validators:yii\base\Model:private] =&gt; 
              [_scenario:yii\base\Model:private] =&gt; default
              [_events:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_eventWildcards:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_behaviors:yii\base\Component:private] =&gt; Array
                  (
                  )
  
          )
  
      [1] =&gt; home\models\User Object
          (
              [_id] =&gt; 
              [id] =&gt; 
              [username] =&gt; 
              [password] =&gt; 
              [role] =&gt; 
              [_attributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b1
                          )
  
                      [id] =&gt; 2
                      [username] =&gt; admin2
                      [password] =&gt; admin2
                      [role] =&gt; 20
                  )
  
              [_oldAttributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b1
                          )
  
                      [id] =&gt; 2
                      [username] =&gt; admin2
                      [password] =&gt; admin2
                      [role] =&gt; 20
                  )
  
              [_related:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_relationsDependencies:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_errors:yii\base\Model:private] =&gt; 
              [_validators:yii\base\Model:private] =&gt; 
              [_scenario:yii\base\Model:private] =&gt; default
              [_events:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_eventWildcards:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_behaviors:yii\base\Component:private] =&gt; Array
                  (
                  )
  
          )
  
      [2] =&gt; home\models\User Object
          (
              [_id] =&gt; 
              [id] =&gt; 
              [username] =&gt; 
              [password] =&gt; 
              [role] =&gt; 
              [_attributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b3
                          )
  
                      [id] =&gt; 3
                      [username] =&gt; admin3
                      [password] =&gt; admin3
                      [role] =&gt; 20
                  )
  
              [_oldAttributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b3
                          )
  
                      [id] =&gt; 3
                      [username] =&gt; admin3
                      [password] =&gt; admin3
                      [role] =&gt; 20
                  )
  
              [_related:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_relationsDependencies:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_errors:yii\base\Model:private] =&gt; 
              [_validators:yii\base\Model:private] =&gt; 
              [_scenario:yii\base\Model:private] =&gt; default
              [_events:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_eventWildcards:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_behaviors:yii\base\Component:private] =&gt; Array
                  (
                  )
  
          )
  
      [3] =&gt; home\models\User Object
          (
              [_id] =&gt; 
              [id] =&gt; 
              [username] =&gt; 
              [password] =&gt; 
              [role] =&gt; 
              [_attributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b5
                          )
  
                      [id] =&gt; 4
                      [username] =&gt; user
                      [password] =&gt; user
                      [role] =&gt; 10
                  )
  
              [_oldAttributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b5
                          )
  
                      [id] =&gt; 4
                      [username] =&gt; user
                      [password] =&gt; user
                      [role] =&gt; 10
                  )
  
              [_related:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_relationsDependencies:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_errors:yii\base\Model:private] =&gt; 
              [_validators:yii\base\Model:private] =&gt; 
              [_scenario:yii\base\Model:private] =&gt; default
              [_events:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_eventWildcards:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_behaviors:yii\base\Component:private] =&gt; Array
                  (
                  )
  
          )
  
      [4] =&gt; home\models\User Object
          (
              [_id] =&gt; 
              [id] =&gt; 
              [username] =&gt; 
              [password] =&gt; 
              [role] =&gt; 
              [_attributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b7
                          )
  
                      [id] =&gt; 5
                      [username] =&gt; user2
                      [password] =&gt; user2
                      [role] =&gt; 10
                  )
  
              [_oldAttributes:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                      [_id] =&gt; MongoDB\BSON\ObjectId Object
                          (
                              [oid] =&gt; 5c3da90384274926934b86b7
                          )
  
                      [id] =&gt; 5
                      [username] =&gt; user2
                      [password] =&gt; user2
                      [role] =&gt; 10
                  )
  
              [_related:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_relationsDependencies:yii\db\BaseActiveRecord:private] =&gt; Array
                  (
                  )
  
              [_errors:yii\base\Model:private] =&gt; 
              [_validators:yii\base\Model:private] =&gt; 
              [_scenario:yii\base\Model:private] =&gt; default
              [_events:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_eventWildcards:yii\base\Component:private] =&gt; Array
                  (
                  )
  
              [_behaviors:yii\base\Component:private] =&gt; Array
                  (
                  )
  
          )
  
  )
  </code></pre>
  
  <p>Can you tell me what step made me call BaseActiveRecord? And how to make the array visible?
  Maybe just like this for every document</p>
  
  <pre><code>(
      [_id] =&gt; 5c3da90384274926934b86b3
      [id] =&gt; 3
      [username] =&gt; admin3
      [password] =&gt; admin3
      [role] =&gt; 20
  )
  </code></pre>