I am new with yii2 and I am having issues printing data from 2 different tables.
//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>
Seems like I dont understand the way yii2 works with table connections... what am i missing?
thanks