如何为多列显示字段使用自定义格式?

How to use a custom format for multi-column display fields?

是否有人知道扩展此 'normal' 用途的方法(默认情况下为 id 并且很容易更改为 field1)?我有一个 displayField 集如下:

$this->displayField(['name', 'desc']);

在模板文件中调用时显示为 Name; Description。我知道这是一个软糖,但是有一种方法我可以操纵它让它显示 Name - Description 例如,只需使用 displayField?

使用虚拟字段,并指定将其用作显示字段而不是使用多列,类似于

// ...

class YourEntity extends Entity
{
    // ...

    protected function _getNameDesc()
    {
        return
            $this->_properties['name'] .
            ' - ' .
            $this->_properties['desc'];
    }
}
// ...

class YourTable extends Table
{
    // ...

    public function initialize(array $config)
    {
        $this->displayField('name_desc');

        // ...
    }
}

另见