2

就我而言,我有一个后端列表,并且我在列表中获得了更新的 UserId。但我不知道如何显示用户名而不是用户 ID。有没有人可以帮助我摆脱这种情况? 在此处查看列表

4

2 回答 2

1

嗨,您必须使用关系字段类型,更改您的columns.yamland 而不是使用user_id以下内容:

user:
 label: Username
 type: relation
 select: login

记住userbelongsTo数组中定义的关系名称

您应该在模型中定义正确的关系

<?php

class YourModel extends Model
{
  $belongsTo = ['user'=>'Backend\Models\User'];
}

欲了解更多信息http://octobercms.com/docs/backend/lists#column-relation

于 2017-09-15T23:48:52.960 回答
0

在 YourModel.php 中,添加此关系

public $hasOne = [
        'user' => ['Backend\Models\User', 'key' => 'id', 'otherKey' => 'user_id']
            ];

在你的 columns.yaml 中,添加这个

 user:
        label: 'Username'
        type: text
        select: username //field from users table
        relation: user //relation name is the key defined in model "hasone" relation

于 2017-11-23T10:47:48.653 回答