title: Yii2 display data after join
body: <p>I have joined 2 table, now I want to show the name of categories in field <code>&lt;th&gt;Categories name&lt;/th&gt;</code>. How can I do that with <code>&lt;?php foreach ($posts as $post){ ?&gt;</code> ? Do i render like <code>&lt;?=$post-&gt;categories.name?&gt;</code> ? I'm stuck here.</p>
  
  <p>Thank you.</p>
  
  <p>My controller:</p>
  
  <pre><code>  public function actionIndex()
  {
  
       $query = posts::find()-&gt;leftJoin('categories', 'posts.cate_id = categories.id');
       $cates = Categories::find()-&gt;all();
       $posts= $query-&gt;orderBy(['create_date' =&gt; SORT_DESC])-&gt;all();
       $images = Images::find()-&gt;all();
       $searchModel = new PostsSearch();
      $dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;queryParams);
  
      return $this-&gt;render('index', [
          'posts' =&gt; $posts,
          'dataProvider' =&gt; $dataProvider,
              'searchModel' =&gt; $searchModel,
              'cates' =&gt; $cates,
              'images' =&gt; $images,
      ]);
  }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;thead&gt;
  &lt;tr&gt;
      &lt;th&gt;ID&lt;/th&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Create Date&lt;/th&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;?php foreach ($posts as $post){ ?&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;?= $post-&gt;id ?&gt;&lt;/td&gt;
  
       &lt;th&gt;&lt;?= Html::a($post-&gt;name, ['post/view', 'id'=&gt;$post-&gt;id]) ?&gt;&lt;/th&gt;
  
      &lt;td&gt;&lt;?= $post-&gt;create_date ?&gt;&lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;?php } ?&gt;
       &lt;/tbody&gt;
  </code></pre>