Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用多个表数据yii2_Yii2_Yii2 Basic App_Yii2 Model - Fatal编程技术网

使用多个表数据yii2

使用多个表数据yii2,yii2,yii2-basic-app,yii2-model,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

我是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>
//在模型末尾
公共函数getTeam()
{
返回$this->hasOne(Team::className(),['id'=>'Team_id']);
}
//在控制器中
公共函数actionPlay()//IRA不符合规则
{
$player=player::find()
->leftJoin('team','id=team\u id')
->订购人('player_id')
->全部();
返回$this->render('play',['player'=>$player])
}
调用视图
HTML/PHP
似乎我不明白yii2处理表连接的方式。。。 我错过了什么


感谢

未知属性–yii\base\UnknownPropertyException in dir/filename.php yii\db\BaseActiveRecord::u get('team_name')参考您必须使用关系try
$player->team->team_name
非常感谢。。。我想我没走那么远,我的错误是$player->$team->team\u name