title: Two Models Displaying to Same View in Yii2
body: <p>I am trying to get information from two models that are related, displayed in one view.</p>
  
  <p>So what I am trying to accomplish is have the index view to show the list of people, if I then go into detail view of that particular person I want a list of attributes relevant to that person to appear. </p>
  
  <p>I have the database setup so that when I create a new person a default row gets inserted into the attributes table with the id of the person under the column called person_id.</p>
  
  <p>See my two model classes </p>
  
  <p>People:</p>
  
  <pre><code>class People extends \yii\db\ActiveRecord
  {
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'people';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['dob', 'CURDATE'], 'safe'],
              [['age'], 'integer'],
              [['firstname', 'surname'], 'string', 'max' =&gt; 50]
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'id' =&gt; 'ID',
              'firstname' =&gt; 'Firstname',
              'surname' =&gt; 'Surname',
              'dob' =&gt; 'Dob',
              'age' =&gt; 'Age',
              'CURDATE' =&gt; 'Curdate',
          ];
      }
  
      /**
       * @return \yii\db\ActiveQuery
       */
      public function getId0()
      {
          return $this-&gt;hasOne(Attributes::className(), ['person_id' =&gt; 'id']);
      }
  }
  </code></pre>
  
  <p>Attributes:</p>
  
  <pre><code>class Attributes extends \yii\db\ActiveRecord
  {
      /**
       * @inheritdoc
       */
      public static function tableName()
      {
          return 'attributes';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['haircolor', 'eyecolor', 'weight', 'height', 'person_id'], 'required'],
              [['weight', 'height', 'person_id'], 'integer'],
              [['haircolor', 'eyecolor'], 'string', 'max' =&gt; 50]
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'id' =&gt; 'ID',
              'haircolor' =&gt; 'Haircolor',
              'eyecolor' =&gt; 'Eyecolor',
              'weight' =&gt; 'Weight',
              'height' =&gt; 'Height',
              'person_id' =&gt; 'Person ID',
          ];
      }
  
      /**
       * @return \yii\db\ActiveQuery
       */
      public function getPeople()
      {
          return $this-&gt;hasOne(People::className(), ['id' =&gt; 'person_id']);
      }
  }
  </code></pre>
  
  <p>I have generated CRUD through Gii for both of these models.</p>
  
  <p>What I would like to know is how to setup my people controller and people view so that this may work properly. </p>
  
  <p>Just to recap, my index.php view will just show the list of people, if a record exists, you can view that specific record, if you view the record - which will be the view.php file, I want to show the attributes(These will be the default values) of that particular person where the id of the person is the same as the person_id in the attributes table</p>
  
  <p>The user will then be able to update the attributes relating to that person.</p>
  
  <p>Kind Regards.</p>