使用多个表数据yii2

时间:2016-03-14 09:29:36

标签: yii2 yii2-basic-app yii2-model

我是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与表连接一起工作的方式...... 我错过了什么?

感谢

0 个答案:

没有答案