title: yii2 how to get relations and get title of id using foreign key
body: <p>i have model of events , and one event have one project , one to one association and i have write function in Event model to get project as below</p>
  
  <pre><code> public function getprojects() {
      return $this-&gt;hasOne(app\models\Project::className(), ['id' =&gt; 'projectid']);
  }
  </code></pre>
  
  <p>and below is code of my controller </p>
  
  <pre><code>if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
              $project = $model-&gt;project;
              return $this-&gt;redirect(['eventdetail', 'id' =&gt; $model-&gt;id, 'project' =&gt; $project]);
          }
  </code></pre>
  
  <p>and Detail view code is </p>
  
  <pre><code> &lt;?= DetailView::widget([
          'model' =&gt; $model,
          'attributes' =&gt; [
              'id',
              'projectid',
              'userid',
              'milestone',
              'datetime',
          ],
      ]) ?&gt;
  </code></pre>
  
  <p>I want to print Title of project instead of projectid , and we get title from associated table how i get title and print in detail view</p>