1
我有一个名为hosts的表,另一个表是hostgroup。在我的主机桌上它有这些字段:ID,名称和hostgroup_id
。在我的hostgroup
表中,它的字段也是id
和name
。我想从主机表中显示view/index.php
,显示其id
,name
和根据其id
从主机组表hostgroup.name
。 Also, do you have any idea how I can make it redirect to the
更新page of
hostgroup`那个特定的ID?在GridView中显示另一个表的字段Yii 2
在我main_directory/model/HostsSearch.php
我有这样的:
public function getHostgroup()
{
return $this->hasOne(HostgroupsSearch::className(), ['id' => 'parent_host_id']);
}
虽然在我main_dir/view/hosts/index.php
我有这样的:
<?=
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'id',
'name',
'parent_host_id.name',
[
'label' => 'Name',
'value' => 'HostgroupsSearch.name',
],
'ip_address',
'object_name',
],
?>
将此'getHostgroup()'函数添加到您的模型文件 – vishuB