PHP:如何基于id将来自其他模型的数据显示为外键?
我有一个使用yii2框架的应用程序 我的应用程序有一个包含表的数据库:PHP:如何基于id将来自其他模型的数据显示为外键?,php,gridview,yii2,kartik-v,Php,Gridview,Yii2,Kartik V,我有一个使用yii2框架的应用程序 我的应用程序有一个包含表的数据库: 类=> id=>asPK 类名 教师id 学生=> 身份证 class_id=>asclass_id作为class表中的外键 学生姓名 年龄 性 等 在我的index.php(类)中,我使用了Kartik Gridview来显示类的数据。 正如您所知,gridview中有许多操作,例如查看按钮操作。 例子: Myindex.php以gridView格式显示class中id=101的数据 如何显示学生表中具有类i
类
=>
- id=>asPK
- 类名
- 教师id
学生
=>
- 身份证
- class_id=>asclass_id作为
表中的外键class
- 学生姓名
- 年龄
- 性
class
中id=101的数据
如何显示学生
表中具有类id
=101的所有学生名
?
我有以下代码:
在我的类中。php在我的类模型中
和我的gridView的代码
我的类视图中的view.php
详细视图的:
'value' => implode(',', \yii\helpers\ArrayHelper::map($model->fakturOutDetails, 'id', 'student_name')),
'value' => function($model) {
return implode(',', \yii\helpers\ArrayHelper::map($model->fakturOutDetails, 'id', 'student_name')),
},
对于GridView
:
'value' => implode(',', \yii\helpers\ArrayHelper::map($model->fakturOutDetails, 'id', 'student_name')),
'value' => function($model) {
return implode(',', \yii\helpers\ArrayHelper::map($model->fakturOutDetails, 'id', 'student_name')),
},
更新您的问题并添加调用view.php(我认为是index.php)和view.php的控制器/操作的代码