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

主宰稳场 提交于 2019-12-01 07:50:06

问题


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

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?


回答1:


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

        // ...
    }
}

See also

  • Cookbook > Database Access & ORM > Entites > Creating Virtual Fields


来源:https://stackoverflow.com/questions/38425881/how-to-use-a-custom-format-for-multi-column-display-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!