0

我是 yii2 的新手,我在打印来自 2 个不同表的数据时遇到问题。

//at the end of the model
public function getTeam()
  {
    return $this->hasOne(Team::className(), ['id' => 'team_id']);
  }

// in the controller
public function actionPlay() // IRA no consigo que rule la relacion entre piloto y equipo
  {
    $player = Player::find() 
            ->leftJoin('team', 'id=team_id')
            ->orderBy('player_id')
            ->all();

    return $this->render('play', [ 'player' => $player ])
  }

Calling the view
<?= $this->render('card/play-steps', ['player'=>$player]) ?>

HTML / PHP
<span><?= $player->player_name ?></span>
<span><?= $player->team_name ?></span>

好像我不明白 yii2 处理表连接的方式......我错过了什么?

谢谢

4

0 回答 0