如何组合名字和姓氏,然后在“奏鸣曲”管理中的“全名”列中显示

时间:2019-06-04 10:28:34

标签: php symfony sonata-admin symfony-4.2

我正在尝试显示实体中具有firstName和lastName的全名列。我该怎么办?

这是我的实体和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)
}

1 个答案:

答案 0 :(得分: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;
}