use*_*652 1 symfony sonata-admin
显示奏鸣曲的列表形式。我有 2 个字段:名字、姓氏。我想在同一列中显示 2 个字段。
目前,我正在做
$listMapper->add('firstname', 'text', array('label' => 'First Name'))
->add('lastname', 'text', array('label' => 'Last Name'));
Run Code Online (Sandbox Code Playgroud)
如何在不更改实体的情况下将两个字段合并为一个
我就是这样做的:
假设firstname和lastname是用户的属性。在您的实体类 User 中,只需添加:
/**
* @return string
*/
public function getFullname()
{
return sprintf("%s %s", $this->getFirstname(), $this->getLastname());
}
Run Code Online (Sandbox Code Playgroud)
然后在你的管理类中:
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
...
->add('fullname', null, array('label' => 'Full Name'))
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2698 次 |
| 最近记录: |