我正在尝试显示实体中包含名字和姓氏的全名列。我该怎么办?
这是我的实体和 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)
}
尝试在您的用户实体中使用它:
/**
* 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;
}