如何组合名字和姓氏,然后在Sonata管理中将其显示在全名栏中

问题描述 投票:0回答: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)
}
php symfony sonata-admin
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;
}
© www.soinside.com 2019 - 2024. All rights reserved.