-1

我正在尝试使用实体中的名字和姓氏显示全名列。我能怎么做?

这是我的实体和 Admin.php:

class test{

private firstName;

//another properties

private lastName;

}

行政

protected function configureListFields(ListMapper $listMapper){
$listMapper
  ->add('id',null)
  ->add('Full name'); //I want to show the column like this (Full name = firstName + lastName)
}
4

1 回答 1

0

尝试在您的用户实体中使用它:

    /**
 * Get the full username if first and last name are set,
 * the username otherwise
 *
 * @return string
 */
public function getFullUsername(): string
{
    if ($this->firstname && $this->lastname) {
        return $this->firstname . ' ' . $this->lastname;
    }

    return $this->username;
}
于 2019-06-04T11:14:53.783 回答