我正在尝试显示实体中具有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)
}
答案 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;
}