奏鸣曲 2 在同一列中显示 2 个字段 [英] Sonata 2 display 2 fields in the same column

查看:37
本文介绍了奏鸣曲 2 在同一列中显示 2 个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示奏鸣曲的列表形式.我有 2 个字段:名字,姓氏.我想在同一列中显示 2 个字段.

I display the list form of Sonata. I have 2 fields : firstname, lastname. I want to display 2 fields in the same column.

目前,我正在做

$listMapper->add('firstname', 'text', array('label' => 'First Name'))
           ->add('lastname', 'text', array('label' => 'Last Name'));

如何在不更改实体的情况下将 2 个字段合二为一

How can I combine 2 fields in one without to change the Entity

推荐答案

我是这样做的:

firstnamelastname 是User 的属性.在您的实体类 User 中,只需添加:

Say firstname and lastname are properties of User. In your entity class User, just add:

/**
 * @return string
 */
public function getFullname()
{
    return sprintf("%s %s", $this->getFirstname(), $this->getLastname());
}

然后在您的管理课程中:

Then in your admin class:

/**
 * {@inheritdoc}
 */
protected function configureListFields(ListMapper $listMapper)
{
  $listMapper
  ...
     ->add('fullname', null, array('label' => 'Full Name'))
}

这篇关于奏鸣曲 2 在同一列中显示 2 个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆