如何为多列显示字段使用自定义格式? [英] How to use a custom format for multi-column display fields?

查看:190
本文介绍了如何为多列显示字段使用自定义格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道一种扩展这种方法的正常用法(默认情况下是 id ,并且容易改为 field1 )?我有一个displayField集合如下:

Is anyone aware of a way of expanding the 'normal' uses of this (it's id by default and easily changed to field1)? I have one displayField sets follows:

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

显示为描述在模板文件中调用时。我知道这是一个fudge,但它有一种方式,我可以操纵这个显示名称 - 描述例如,只需使用 displayField

Which displays as Name; Description when called in a template file. I know it's a fudge, but it there a way I can manipulate this to have it display Name - Description for example, just by using the displayField?

推荐答案

使用虚拟字段,并指定用作显示字段列,

Use a virtual field, and specify that to be used as display field instead of using multiple columns, something along the lines of

// ...

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');

        // ...
    }
}

另请参阅

这篇关于如何为多列显示字段使用自定义格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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